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 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