Problem with indexing a series of ranges
2 views (last 30 days)
Show older comments
Silvia Marchesi
on 2 Jun 2022
Commented: Silvia Marchesi
on 2 Jun 2022
Hello,
I know my level is very basic, but I read a lot and I couldn't find the solution I need.
I am using a function to calculate the max value of an array in segments of 75 values (max value of the segment from 1 to 75, max value of the segment from 76 to 150...and so on).
I am using
Max = max(reshape(data, 75, []))
it is working very well.
But as now I need to have also the indexing of it I tried with
[Max, iMax] = max(reshape(data, 75, []))
but it gives me the indexing of the values inside their segment (always a number from 1 to 75) while I would need the originary indexing.
Any idea?
Thank you!
Silvia
0 Comments
Accepted Answer
Stephen23
on 2 Jun 2022
Edited: Stephen23
on 2 Jun 2022
Use MAX's "linear" option:
M = randi(9,5,7)
[V,X] = max(M, [], 'linear')
To be robust you should also specify the dimension:
[V,X] = max(M, [], 1, 'linear');
Just for comparison, without the "linear" option for each column the relevant row index is returned:
[~,Y] = max(M)
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements 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!