exit from loop

1 回表示 (過去 30 日間)
huda nawaf
huda nawaf 2011 年 10 月 12 日
hi, in the following code,I need when mat(k,2)=map(j,2)exit of loop.
for j=1:i
for k=1:L
if map(j,1)==mat(k,2)
mat(k,2)=map(j,2);
end
end
end

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 10 月 12 日
leave_early = false;
for j=1:i
if leave_early; break; end
for k=1:L
if map(j,1)==mat(k,2)
mat(k,2)=map(j,2);
leave_early = true;
break
end
end
end
  2 件のコメント
Andrei Bobrov
Andrei Bobrov 2011 年 10 月 12 日
[i1,j1] = find(bsxfun(@eq,map(:,1)',mat(:,2)),1,'first');
mat(i1,2)=map(j1,2);
Jan
Jan 2011 年 10 月 12 日
@Andrei: Please post this as an answer.

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

カテゴリ

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