How to get Matlab to include all expression sizes on error because dimensions are not consistent?

So, I am debugging some Matlab code, and for some expressions I get a measurement-disagree error. All is well that Matlab points to the correct line, etc. However, it would be nice if Matlab returned the sizes of the variables involved in the error text, so I do not need to understand myself. Sometimes for a long expression deep in a for loop, it is a real hassle to figure out what all dimensions are.

So is there a tweak or hack this?

+4
source share
2 answers

The easiest way to deal with this problem is to enter dbstop if error in the command window, and then run the code. MATLAB will stop execution before it throws an error and open the editor in the line where the error will be displayed. Then you can check the sizes of the arrays at your leisure, and even in the command window you can check for possible corrections, because you will have access to all the variables that are currently active in the code.

+7
source

You can try the try-catch-end .

eg.

 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 a breakpoint in the catch block if you want to evaluate things yourself.

+2
source

Source: https://habr.com/ru/post/1315126/


All Articles