So I am debugging some Matlab code and I get the dimension-doesn't-agree-error for some expressions. It's all nice that Matlab points to the correct line etc. However it would be nice if Matlab would output the dimensions of the variables involved in the error text so I don't have to deal with sizing them up myself. Sometimes for a long expression deep in a for loop it's a real hassle to figure out what exactly all dimensions are.
So is there a setting or hack for this?
The easiest way to deal with this issue is to type dbstop if error
in the command window, and then to run the code. MATLAB will then stop execution right before it would throw the error, and it will open the editor on the line where the error would be thrown. Then you can inspect the array sizes at your leisure, and you can even, in the command window, try out possible fixes, because you will have access to all the variables currently active in the code.
You can try the try-catch-end
block.
E.g.
try
%# Some error prone code
a = getA(b);
catch err_msg
%# Display any information you want
disp(size(b));
%# Display the error message
disp(err_msg.identifier);
disp(err_msg.message);
end
You can also throw in a breakpoint in the catch block if you want to evaluate things yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With