in a loop like go back

1 回表示 (過去 30 日間)
Lev Mihailov
Lev Mihailov 2019 年 9 月 19 日
編集済み: Matt J 2019 年 9 月 19 日
Hello! Now I use this loop
for i=1:length(data)
if a(i)<=1
a(i)=a(i-1)
end
end
but I was faced with the calculation that the zones of zero values ​​and they give me the wrong result
a(i)=a(i-1) % find(a)
what’s the best way to write, not a (i-1), but write a (i up to the first value that meets the if condition)

回答 (1 件)

Matt J
Matt J 2019 年 9 月 19 日
編集済み: Matt J 2019 年 9 月 19 日
first=find(a<=1, 1);
a(1:first)

カテゴリ

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