Why is matlab busy?

12 ビュー (過去 30 日間)
Robert Haxhari
Robert Haxhari 2020 年 9 月 28 日
コメント済み: Steven Lord 2020 年 9 月 28 日
I'm trying a basic script and working some things out for a base on a much more compliacted script, but for some reason MATLAB can't run the whole script and stays busy and never finishes? The script says there's nothing wrong with it so I just don't understand why it is forever busy.
Script:
r = ones(1,10);
i = 1;
while i <= length(r)
r(i) = 0;
i = 1+1;
end
it does the first two elements then stops.

採用された回答

Steven Lord
Steven Lord 2020 年 9 月 28 日
i = 1+1;
Did you mean to add 1 to i rather than adding 1 to 1? The length of r is greater than 2, so the condition of your while statement is always satisfied. You have an infinite loop.
  2 件のコメント
Robert Haxhari
Robert Haxhari 2020 年 9 月 28 日
Oh my god I'm an idiot, thank you so much this was driving me crazy!!
Steven Lord
Steven Lord 2020 年 9 月 28 日
As a general suggestion, when you encounter a situation like this in the future I recommend using the debugging tools built into MATLAB to step through the code (section by section or line by line) to determine specifically where the problem is introduced.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by