Find the maximum value in each group of a big matrix
Show older comments
I have a big matrix and I'm looking for an easy way to group them by a certain way then find the maximum in each group. I have created this code but I got stuck. Anyway to help please. I need to know the indexes of all the maximum points to extract more information from the big matrix.
data = randn(10,1)*10;
edges = 0:5:35';
Y = discretize(data,edges);
[B,I] = sort(Y);
SortedMatrix = [B data(I)];
5 Comments
Jan
on 26 Apr 2019
What does "group them by a certain way" mean? What exactly are "the indices of all the maximum points"? Please post a small example or define the procedure exactly.
Yaser Khojah
on 26 Apr 2019
Yaser Khojah
on 26 Apr 2019
So is sortedMatrix your actual input data? Or do you want to process data, which is set to a random array for a demonstration?
It would be easier, if you avoid to create the NaNs, e.g. by adding a final edge Inf. Then splitapply(@max, data(I), B) would solve the problem.
Yaser Khojah
on 26 Apr 2019
Edited: Yaser Khojah
on 26 Apr 2019
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!