Problem with indexing a series of ranges

2 views (last 30 days)
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

Accepted Answer

Stephen23
Stephen23 on 2 Jun 2022
Edited: Stephen23 on 2 Jun 2022
Use MAX's "linear" option:
M = randi(9,5,7)
M = 5×7
9 4 4 3 3 5 8 2 6 1 3 9 1 2 4 5 3 8 8 1 4 5 1 3 3 4 5 3 9 6 4 2 4 7 1
[V,X] = max(M, [], 'linear')
V = 1×7
9 6 4 8 9 7 8
X = 1×7
1 7 11 18 22 30 31
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)
Y = 1×7
1 2 1 3 2 5 1

More Answers (0)

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!