How can adding a breakpoint cause an error?
이전 댓글 표시
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
(other code)
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!
댓글 수: 1
Matt J
2013년 1월 26일
It doesn't seem like you've shown your actual code. There are no subscripts in the line where you claim to see the error. A few preliminary recommendations
- Show your actual code if you're not doing so
- Paste your error messages in their entirety.
- Use "dbstop if error" and see where the code stops and what the state of value2 etc... is at that point
답변 (3개)
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.
댓글 수: 4
Natalie
2013년 1월 25일
Matt J
2013년 1월 26일
Personally, it's now hard to see the correspondence between the pseudocode that you originally posted and the actual code that you've posted immediately above. I recommend you annotate the second version of the code as you did the first, saying where you set breakpoints, what steps you perform to produce the error and a copy/paste of the EXACT AND COMPLETE error messages.
Matt J
2013년 1월 28일
Trap this error with DBSTOP IF ERROR. Then evaluate
>> f, 1:length(objc2D)
Is it possible that you've run, reached a breakpoint, then run again without first quitting out of DEBUG mode?
댓글 수: 3
Similarly, is this a script or a function? If it's a script, then is it possible that you ran until reaching a breakpoint, quit out of debug mode, then ran again forgetting to clear all the variables from the base workspace of the changes induced by your previous run?
Natalie
2013년 1월 26일
Matt J
2013년 1월 26일
No persistent variables either? What if you do "clear functions" first, and then set the breakpoints again and run?
Image Analyst
2013년 1월 26일
편집: Image Analyst
2013년 1월 26일
Set a breakpoint at this line:
B = value2; % the error is for this line if there is a breakpoint
before you execute it, say this in the command line:
K>> whos value2
K>> size(value2)
Tell us what it says.
댓글 수: 2
Natalie
2013년 1월 28일
Image Analyst
2013년 1월 29일
Now do the same thing for out2d.objc2 (instead of objc2). You're saying that it's a 2D array, but is it really?
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!