exit from loop
3 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
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
2011-10-12
[i1,j1] = find(bsxfun(@eq,map(:,1)',mat(:,2)),1,'first');
mat(i1,2)=map(j1,2);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!