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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by