Questions tagged [accumarray]

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.

66 questions
3
votes
1 answer

Improve code / remove for-loop when using accumarray MATLAB

I have the following piece of code that is quite slow to compute the percentiles from a data set ("DATA"), because the input matrices are large ("Data" is approx. 500.000 long with 10080 unique values assigned from "Indices"). Is there a…
Jonas
  • 308
  • 1
  • 11
3
votes
1 answer

Using accumarray to sum data in Matlab

I have a matrix like this: >>D=[1,0,10;3,1,12;3,1,12.5;6,1,6;6,2,11.1;] D = 1.0000 0 10.0000 3.0000 1.0000 12.0000 3.0000 1.0000 12.5000 6.0000 1.0000 6.0000 6.0000 2.0000 11.1000 I want to get the sum of the second…
Natalia
  • 369
  • 3
  • 15
3
votes
2 answers

Matlab using accumarray with cell array

I am quite new to Matlab, but I have some experience with other programming languages. I have a very large table imported from MySQL in Matlab. It is given as cell array that looks something like this: date key sales weight name 12/11 …
3
votes
3 answers

Calculating a 2D joint probability distribution

I have many points inside a square. I want to partition the square in many small rectangles and check how many points fall in each rectangle, i.e. I want to compute the joint probability distribution of the points. I am reporting a couple of common…
user2875617
3
votes
1 answer

Fun depending on order of subs and values in accumarray

In accumarray() the first note about 'subs', first appeared in the MATLAB R14sp3 docs, says: Note If the subscripts in subs are not sorted, fun should not depend on the order of the values in its input data. It is not clear to me what is…
Oleg
  • 10,406
  • 3
  • 29
  • 57
2
votes
1 answer

Matlab Accumarray for 3D matrix

I really wish the documentation was more clear on the use of accumarray for N-D size matrices in Matlab. Regardless, I'm totally confused here and looking for some advice. Here's the challenge: I have a 3D matrix of data. ROWS are individual…
tdiddy
  • 123
  • 2
  • 2
  • 9
2
votes
1 answer

Vectorization using accumarray

I want to project the texture of 3D surface (CylCoors 300000x3) into a 2D plane (Image 380x360). For doing so I take every unique value in Z (UniqueZ=unique(CylCoors(:,3))) and and Theta (UniqueTheta=unique(CylCoors(:,1))) and project all the…
McMa
  • 1,568
  • 7
  • 22
2
votes
1 answer

Summing rows by index using accumarray

Can I sum rows or columns over several indices without using a for loop? I have an n by n matrix, M, that represents the co-occurrence of vocabulary terms where n is the length of the vocabulary. I also have a n by n logical mask, L, which…
Cecilia
  • 4,512
  • 3
  • 32
  • 75
2
votes
2 answers

Cumulative sum matlab for loop

I am trying to cumulatively sum consecutive hours(variables 'hrs') between hurricane observations for all observations in a particular storm and among multiple storms in order to determine the duration of the storm. This is what I have: stormid =…
runnere127
  • 21
  • 3
2
votes
3 answers

Using accumarray and @min to extract min from groups but also output corresponding values from another variable/column

I have 3 columns of data: time = [1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16]; category = [1;1;1;1;2;2;2;2;3; 3; 3; 3; 4; 4; 4; 4]; data = [1;1;0;1;2;2;1;2;3; 3; 2; 3; 4; 4; 4; 3]; I am using the following to extract the minimum data values for…
Jo.
  • 23
  • 2
2
votes
2 answers

How to convert decimal hour and calculate the average every 5 min?

I'm a beginner at Matlab and I need to solve a problem. First, I need to convert the UT columm from decimal hour to hour:minute:seconds. Then, I need to calculate every 5 minutes on average the ROT collumn and show the reply in a new matrix…
2
votes
1 answer

Find row-wise minima in sparse matrix

I would like to get the minimum nonzero values per row in a sparse matrix. Solutions I found for dense matrices suggested masking out the zero values by setting them to NaN or Inf. However, this obviously doesn't work for sparse matrices. Ideally, I…
Lisa
  • 3,365
  • 3
  • 19
  • 30
2
votes
1 answer

MatLab accumarray unexpectedly changing ordering

As long as I understood accumarray, it means "Making the nth row of the output: 1) find n in sub. 2) if n is in m1, m2, m3 th element in sub, 3) apply the function to m1,m2,m3 th element of val 4) that's the nth row of the output" Am I wrong…
user1849133
  • 527
  • 1
  • 7
  • 18
2
votes
2 answers

matlab - only keep days where 24 values exist

Say that I have a dataset: Jday = datenum('2009-01-01 00:00','yyyy-mm-dd HH:MM'):1/24:... datenum('2009-01-05 23:00','yyyy-mm-dd HH:MM'); DateV = datevec(Jday); DateV(4,:) = []; DateV(15,:) = []; DateV(95,:) = []; Dat =…
Emma
  • 618
  • 12
  • 26
1
vote
1 answer

Count number of observations by group matlab

I have a matlab dataset that looks like this: year value 1995 90000 1995 53000 1995 80000 1995 60000 1995 37000 1995 42000 1995 13102 1996 35000 1996 50000 1996 32000 1996 47000 1997 36000 1997 90000 1997 …
phdstudent
  • 1,060
  • 20
  • 41