How top stop for loop if value is reached

2 ビュー (過去 30 日間)
will99
will99 2019 年 4 月 18 日
編集済み: James Tursa 2019 年 4 月 19 日
Z is 2000 by 2000 matrix filled with values
I have this for loop I want it to stop when there is no change in the matrix X
so if by the 200 itration there is not a huge change in the vector 199 and 200 stop the loop
for c = 1:2000
X(c+1,:) = X(c,:)*Z;
end

採用された回答

James Tursa
James Tursa 2019 年 4 月 18 日
編集済み: James Tursa 2019 年 4 月 19 日
if( norm(X(c+1,:)-X(c,:)) < some_tolerance )
break;
end
or perhaps
if( all(abs(X(c+1,:)-X(c,:))) < some_tolerance )
break;
end
In the second example, some_tolerance could be a vector if you wanted to apply different tolerances to different elements

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by