how to increment variable while logical true?
14 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I am new to matlab, I want to increment a number when its true.
i tried doing this as a script
global variable;
variable = true;
while (variable)
a=1;
a=a+1;
dips(a);
end
shouldn't this display an incremented value
1
2
3
4
.
.
.
but all i get is
2
2
2
2
.
.
Am i doing something wrong? help!
0 件のコメント
採用された回答
Image Analyst
2015 年 1 月 21 日
編集済み: Image Analyst
2015 年 1 月 21 日
You're setting a back equal to 1 inside the loop. Why? That should be outside the loop. I think you should look at this: http://blogs.mathworks.com/videos/2012/07/03/debugging-in-matlab/
global variable;
variable = true;
a = 1;
while variable
a=a+1
if a > 20
variable = false; % Break out of loop.
end
end
その他の回答 (0 件)
参考
カテゴリ
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!