Loop to Identify changes/steps for each column of a matrix
Mostra commenti meno recenti
Dear all,
I've got a matrix, let's call it M.
What I need to do, is to identify all of the values, for each column, that are both less than the maximum seen so far and follow a linear pattern.
Someone kindly helped me to write a code to address the first task (i.e., identify values less than the maximum seen so far), but I still need to meet the second condition, as I didn't realise that the second condition would have occurred in my dataset:
nrows = height(M);
Mx = zeros(size(M));
runningmax = M(1,:);
for nr = 2:nrows
oldrunningmax = runningmax;
runningmax = min(runningmax, M(nr, :));
Mx(nr,:) = M(nr,:) > runningmax | M(nr, :) == oldrunningmax;
end
Mx
Now, the code above correctly identifies all of the values less than the maximum seen so far (red circles in the figure below):

However, I also need to identify the values that deviate from a linear pattern, such as the major steps in the figure below:

I have attached a data sample (M), which is a portion of a column of my matrix (the one in the figure above).
Could you please help me to amend the code above to correctly meet both conditions?
Thanks a lot!
2 Commenti
Jan
il 17 Gen 2023
Do I understand correctly, that the part until "However, I also need" has no relation to the current question? Unrelated information reduce the chance to get a useful answer.
I assume the first part can be simplified using: M < cummax(M, 1) . No loop is required.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Logical in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
