how to define a while statement that when the variable equals a numerical value, ends the code?
古いコメントを表示
Hi,
I want to write a while condition that when variable A gets a numerical value inside the loop, ends the code, otherwise continues to the code...
How can I write this while condition?
Thansks in advance,
Regards...
採用された回答
その他の回答 (1 件)
Titus Edelhofer
2016 年 1 月 19 日
Hi,
I understand the "get's value" is meant as "being not empty" ...?
A = [];
while isempty(A)
% do something, e.g.
A = 42;
end
Titus
2 件のコメント
Titus Edelhofer
2016 年 1 月 19 日
Or, if you want to run while it's not a specified value:
A = 10;
while A~=1
% do something, e.g.
A = A - 1;
end
Titus
Walter Roberson
2016 年 1 月 19 日
And be careful, if your "specified value" is not an integer then it might be difficult to match it exactly due to floating point precision issues.
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!