Array value changing for no apparent reason?? Is it possible there is hidden lines of code?
Show older comments
In the attached photo, you can see the displayed value in the command window changes between the two breakpoints but the only code executed is a display, this shouldn't change the value, whats happening??
3 Comments
dpb
on 30 Jun 2017
I'd guess sweepData is global and updated from an instrument in background...
Veronica yep
on 30 Jun 2017
The problem is that noted in the Answer, but that doesn't reflect the image -- if the coder were identical to and only what this image shows the change would show up between the first two disp calls. Of course, you can't see the timing between output and the initiation so in fact where it does change will be in between those two lines in actuality, you just can't correlate the two from the image alone.
Accepted Answer
More Answers (1)
As far as I can see, the only command, which is executed during the value changes is not display(), but title. Pleas be so kind and post exactly, in which line the value changes. Then you can be sure, that it is either this command, or if the line if not reproducible, it can be a timer or GUI callback. But then sweepData must either be a function, global variable or class. If you explain, what sweepData is and where the change happens, writing an answer would require less guessing.
Of course there can be hidden lines: Scroll to the right. Perhaps some code appears on the right outside the visible area of the editor. Therefore it would be much better to post the code by copy&paste instead of a screenshot, because then the "hidden" code would appear automatically.
7 Comments
Veronica yep
on 30 Jun 2017
Edited: dpb
on 30 Jun 2017
The most important detail is still concealed: What is the type of sweepData? The step functions seems to be not the one from the Matlab toolbox: https://www.mathworks.com/help/control/ref/step.html, or is it? There is no magic remote changing of variables, except that this has been programmed explicitely. So is this a global variable or a class? Do you use any code for creating variables remotely like evalin or assignin and run it during debugging? Does the change happen reproducible at the some code even if you are not debugging?
You screenshot contains this at line 59 and 60:
display(sum(sweepData))%%%%%%%%%%%%%%%%%%%%%%
display(sum(sweepData))%%%%%%%%%%%%%%%%%%%%%%
The posted code the lines:
display(sum(sweepData))%%%%%%%%%%%%%%%%%%%%%%
display(sum(staticSweepData))
Perhaps you have created a P-file and run an older Matlab version? Then stepping through the code shows the contents of the M-file in the editor, but the P-file is evaluated. This can look very strange and I'm happy that this debugging of P-files has been disabled in modern Matlab versions. Use which FUNCNAME -all to check this, replacing FUNCNAME by the name of the function file.
Veronica yep
on 30 Jun 2017
Edited: Veronica yep
on 30 Jun 2017
You can check the class: Stop in the code by a breakpoint. Then type:
class sweepData
isglobal sweepData
which sweepData -all
An alternative idea is a strange bug: Does the toolbox contain compiled C-code (so called mex files)? You can access memory in C without having the permission to do so. Then the value of a variable can change randomly. But then the problem is not reproducible, and most likely Matlab would crash comppletely.
Veronica yep
on 30 Jun 2017
Veronica yep
on 30 Jun 2017
Sorry, a typo:
class(sweepData) % not: class sweepData
But the problem is solved already. Did you see, that I've mentioned the inconsistency between "sweepData" and "staticSweepData" 2 hours ago already?
Categories
Find more on Scripts in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!