dbstop doesn't stop if the line at which is supposed to stop is something like `'else'

3 ビュー (過去 30 日間)
Leo Simon
Leo Simon 2020 年 5 月 7 日
編集済み: Toder 2020 年 5 月 8 日
If you save the code below to, say, mwe.m then at the command prompt type
dbstop in mwe at 4
then call the function, it will ignore the `else` line at which it is asked to stop, and continue on to the end. Is there a way to fix this problem, and make it stop at line 5 rather than 4?
function mwe
if 1 < 2;
disp('true');
else
disp('false');
end
disp('should not get to here');

採用された回答

Toder
Toder 2020 年 5 月 8 日
編集済み: Toder 2020 年 5 月 8 日
The if condition is true, so Matlab executes disp('true'); then jumps to end. Lines 4 and 5 are never executed because only one block of an if-statement is ever executed, and Matlab had already determined the first block would be executed. Try
function mwe
if 3 < 2
disp('true');
else
disp('false');
end
disp('should not get to here');
This stops at line 4 with the dbstop command you used.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDebugging and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by