I'm having problems debugging Matlab code since when I add a breakpoint, I get an error that doesn't happen without the breakpoint:
In my code I have an if statement to detect questionable results and display a message to the command line, but otherwise let the code run which it does with no issues. There were a few questionable results (after many iterations of expected results) that I wanted to investigate so I put a breakpoint within that if statement; however, once I did that, there is a repeatable error regarding the assignment on the line previous to the if statement (so it never gets to the actual breakpoint). The code runs fine without a breakpoint, but has an error with the breakpoint - what causes this?? And how can I avoid it??
I also tried adding a questionableResults = 1 flag and using that to move the breakpoint to later (as below) and putting a breakpoint in the 'other code' and also after the 'if C' statement, but eventually I always get the same error as with the original breakpoint. As soon as I remove the breakpoint, it runs to completion with no errors.
for i = 1:largeNumber (code to find value1 and value2)
if C A = value1; B = value2; % the error is for this line if there is a breakpoint
if A~= B; disp(['Warning: ' num2str(A) ' is not the same as ' num2str(B)]); *original breakpoint* questionableResults = 1; end
if questionableResults *test breakpoint* end
end %if C
*test breakpoint* end %for i
The error is: 'Assignment has more non-singleton rhs dimensions than non-singleton subscripts' and occurs on the with the assignment of B.
Any insight would be appreciated. Thanks!
No products are associated with this question.
The paraphrased pseudo code is less suitable for debugging in a forum. It is very likely that the problem is exactly in this parts of the code you have hidden.
Do you have any eval() or assignin() in your code? The dynamic creation of variables works differently in debug and non-debug mode.
Play games and win prizes!Learn more