maximum value of numerical pattern
Show older comments
Hi Everyone,
I have a problem that I'm slightly struggling with.
I have two arrays which represent the time step (A) and the corresponding iterations at each time step (B).
A = [1 1 1 2 2 2 3 3 3 3 4 4 4 4 4]
B = [1 2 3 1 2 3 1 2 3 4 1 2 3 4 5]
I would like to extract the maximum iteration (from B) for each time step (from A).
So it should look like
C = [1 2 3 4]
D = [3 3 4 5]
Any help is greatly appreciated.
Best regards,
Lloyd
Accepted Answer
More Answers (1)
Adam Danz
on 21 Aug 2018
Differentiate B in order to know when the count restarts. Then use the index of the restart-points to get C and D.
maxIdx = diff([B,-1])<0; % -1 needed to capture last value
C = A(maxIdx);
D = B(maxIdx);
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!