How to iterate a for loop starting from the previous element?

1 vue (au cours des 30 derniers jours)
Enrica Brunetti
Enrica Brunetti le 17 Sep 2020
I want to plot this signal (inv_norm) within this range [o_previous; o]. I have tried to use these lines code, but I have this error ( "Array indices must be positive integers or logical values"), because Matlab doesn't count from 0.
for i= 1 : length(times_2r)
ind33 = times_2r(i);
o = find(times_biceps == ind33);
o_previous = find(times_biceps == times_2r(i-1));
inv = inv_norm(o_previous:o);
figure;
plot(inv);
end

Réponses (1)

Gaurav Garg
Gaurav Garg le 21 Sep 2020
Hi Enrica,
You should recheck lines 3 and 4 (o = find(times_biceps == ind33); o_previous = find(times_biceps == times_2r(i-1));). The documentation tells that output of find function is a matrix. However, array indices can only be positive and logical values.
So, I would recommend you to rewrite the lines 3 and 4, or rewrite line 5 to run over a loop for each value in o_previous and o.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by