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

조회 수: 1 (최근 30일)
Enrica Brunetti
Enrica Brunetti 2020년 9월 17일
답변: Gaurav Garg 2020년 9월 21일
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

답변 (1개)

Gaurav Garg
Gaurav Garg 2020년 9월 21일
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.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by