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

1 visualización (últimos 30 días)
Enrica Brunetti
Enrica Brunetti el 17 de Sept. de 2020
Respondida: Gaurav Garg el 21 de Sept. de 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

Respuestas (1)

Gaurav Garg
Gaurav Garg el 21 de Sept. de 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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by