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

1 view (last 30 days)
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

Answers (1)

Gaurav Garg
Gaurav Garg on 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.

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!