フィルターのクリア

how to stop for loop?

2 ビュー (過去 30 日間)
STamer
STamer 2013 年 7 月 19 日
for j=rr-3
for i=1:rr-1
if X(i)<=t(j) && t(j)<=X(i+1)
N{1}(j,i)=1;
else
N{1}(j,i)=0;
end
end
end
I want when the code catches N{1}(j,i)=1, then for the rest of N{1}(j,i)=0..How can I do this. I tried another ifelse and for lop but didn't work. Do you have any idea?
The program trying to catch N{1}(j,i)=1 and it does it properly.I want it to stop when N{1}(j,i)=0.
  1 件のコメント
nl2605
nl2605 2013 年 7 月 19 日
I am not so sure. But isn't there a break command for it?

サインインしてコメントする。

採用された回答

Jos (10584)
Jos (10584) 2013 年 7 月 19 日

その他の回答 (1 件)

David Sanchez
David Sanchez 2013 年 7 月 19 日
編集済み: Andrei Bobrov 2013 年 7 月 19 日
break will exit the inner for-loop.
for j=rr-3
for i=1:rr-1
if X(i)<=t(j) && t(j)<=X(i+1)
N{1}(j,i)=1;
else
N{1}(j,i)=0;
break; % get out of the for-loop
end
end
end
To get out of both for-loops, you should add a flag
flag=0;
for ii=1:5
ii
if flag==1
break
end
for jj=1:6
jj
if ii==3 && jj==4
disp('broken here')
flag=1;
break;
end
end
end

カテゴリ

Help Center および File ExchangeChemistry についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by