accumarray is a MATLAB function that is used to accumulate elements in a vector or matrix based on another vector or matrix of indices. accumarray is commonly used for calculating histograms, grouping values based on certain criteria or applying specific functions to grouped data once they are grouped with accumarray. It is currently one of the most versatile functions in MATLAB's native library and was available since MATLAB 7, R14.
Questions tagged [accumarray]
66 questions
1
vote
2 answers
Formatting data from an excel sheet (two criteria) in MATLAB
I have a question related to another one recently asked. I download my data as a csv.file. I then format it in MATLAB. I obtan formatted data such as:
I would like to format the data so that I obtain:
In other words, the date should be in the…

Joe
- 457
- 5
- 18
1
vote
1 answer
Count the number of unique values for each column of a submatrix in a fast manner
I have a matrix X with tens of rows and thousands of columns, all elements are categorical and re-organized to an index matrix. For example, ith column X(:,i) = [-1,-1,0,2,1,2]' is converted to X2(:,i) = ic of [x,ia,ic] = unique(X(:,i)), for…

Elkan
- 546
- 8
- 23
1
vote
1 answer
Using accumarray for a weighted average?
accumarray in Matlab is amazing, and I use it often. I have a problem where the function I would like to pass to accumarray is a weighted average. i.e. it takes in two vectors, not a single vector. This appears to be a use case not supported by…

John
- 5,735
- 3
- 46
- 62
1
vote
1 answer
Matlab's Accumarray using Sparse matrix multiplication
I have the following instruction in matlab
out = accumarray (A,B,sz);
where B and A is of size 1x957600 and 957600x1 respectively and sz is [1445 1]. The result out is of 1445x1 size.
My question is how can we implement this instruction without…

Nishant Kapoor
- 23
- 5
1
vote
0 answers
Multithread alternative to accumarray
I am using accumarray() to create a 3D array from a list of xyz coordinates PointCoors and their respective values PointValues like this:
Stack=accumarray([PointCoors(:,1),PointCoors(:,2),PointCoors(:,3)],PointValues,...
…

McMa
- 1,568
- 7
- 22
1
vote
2 answers
matlab - Accumarray Adjacency Matrix Confusion?
So I'm trying to create an adjacency matrix, and I'm confused on the difference between accumarray(matrix+1,1) and accumarray(matrix,1).
I did:
matrix = [ 1 3
4 2
1 3
3 1]
adMatrix1 =…

ocean800
- 3,489
- 13
- 41
- 73
1
vote
1 answer
Fast rolling correlation in Matlab
I am trying to derive a function for calculating a moving/rolling correlation for two vectors and speed is a high priority, since I need to apply this function in an array function. What I have (which is too slow) is this:
Data1 =…

Mace
- 1,259
- 4
- 16
- 35
1
vote
4 answers
Count occurences of strings in column - Matlab
I have a column with the following data:
Size: 100x7
val =
USA
USA
France
USA
France
I want to show the data on pie chart. to do this, I need to know how much USA occur in this column, and so on.
I read about the functions unique,accumarray but I…

Ofir Attia
- 1,237
- 4
- 21
- 39
1
vote
1 answer
Summing data by window size in grouped data
I am quite new to matlab and I am trying to find a way to accomplish the following task without using for loops:
I have a data set looking like this:
data = [1 5; 1 3; 1 8; 2 1; 2 2; 2 5; 3 3; 3 8; 3 4]
the first column is a group (being a month…

Stephan Claus
- 405
- 1
- 6
- 16
1
vote
0 answers
Joint Entropy of audio files
So, after trying a heavy cicle-based function for calculating the joint entropy of two sources of information, I found this useful MATLAB function, accumarray, and tried the following code:
function e = jointEntropy(fonte1, fonte2)
i =…

M. M. F.
- 35
- 10
1
vote
2 answers
Fancy Binning Operation - How to vectorize a relative intra-bin-wise operation?
I've decided to get a little wild this evening and party with histogram bins to operate on some financial data I'm analyzing.
It appears the party has been pooped on, though, as the manner through which I would like to apply my 'intra-bin' operation…

zelusp
- 3,500
- 3
- 31
- 65
1
vote
1 answer
expanded accumarray output for unsorted data in matlab
I am using the accumarray function to sum the values in vector "data" within categories defined by the vector "id". I want my vector id to not be necessarily sorted, and also potentially containing non-consecutive numbers. I also want to end up…

user3026357
- 25
- 5
1
vote
4 answers
remove duplicates in column 1 of array by retaining only that entry in column 1 that has maximum value in column 2
I have a n X 2 matrix which has been formed by appending many matrices together. Column 1 of the matrix consists of numbers that indicate item_ids and column 2 consists of similarity values. Since this matrix has been formed by concatenating many…

anonuser0428
- 11,789
- 22
- 63
- 86
1
vote
2 answers
Accumarray how to set "fun" to use only last obs of each bin
Is there a way to let accumarray drop every observation but the last of each group?
What I had in mind was something similar:
lastobs=accumarray(bin,x,[],@(x){pick the observation with the max index in each group};
To give you an example,…

CAPSLOCK
- 6,243
- 3
- 33
- 56
1
vote
2 answers
How to apply an aggregating function to groups of table (or dataset) rows?
Suppose I have some table (or dataset) object A that includes some factor X (having n distinct values, or "levels") among its variables. Also suppose I have some custom aggregating function agg that takes as input a sequence of rows, and returns a…

kjo
- 33,683
- 52
- 148
- 265