Counter not working in for loop
2 ビュー (過去 30 日間)
古いコメントを表示
I have a counter in a for loop like this:
x = 0;
for i = 1:10
x = x+1;
% code that uses the counter
end
However, when I was debugging and removed the semicolon from the x = x+1 statement I get:
x =
0×1 empty double column vector
When I debugged and used disp(i) and disp(x), it would only display the value of i and not x. Does anyone know how to fix this?
3 件のコメント
Kevin Phung
2019 年 2 月 13 日
it also seems like x is just equivalent to i in every iteration, have you considered just using i?
回答 (1 件)
Star Strider
2019 年 2 月 13 日
We cannot see the ‘code that uses the counter’. Check to see if your code is somehow clearing ‘x’ or setting ‘x’ to [].
4 件のコメント
参考
カテゴリ
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!