How to make assert() debug break?
显示 更早的评论
I attached my solution. Not sure why it's not the default behavior.
function assert1( b )
if nargin < 1
b = 0;
end
if ~b
disp( 'Assertion failed.' );
dbstack
if 0
dbstop in assert.m at 11;
dbclear in assert.m at 11;
else
ST = dbstack;
if length( ST ) > 1
ST = ST(2);
end
fl = ST.file;
ln = ST.line + 1;
cmd = [ 'dbstop in ' fl ' at ' int2str(ln) ];
eval( cmd )
end
end
end
1 个评论
Jan
2022-7-5
What is the behavior of your code? It creates a breakpoint in the next line and Matlab will stop there.
What happens in nested functions, functions attached to a script and in anonymous functions?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Debugging and Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!