Array value changing for no apparent reason?? Is it possible there is hidden lines of code?

3 次查看(过去 30 天)
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 个评论
Veronica yep
Veronica yep 2017-6-30
ah so even though there is no code here changing anything, if the source of the 'sweepData' data is updated, it will update it anyway? I was guessing this, but it always changes at this point in the loop and not anywhere else where sweepData is used
dpb
dpb 2017-6-30
编辑:dpb 2017-7-1
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.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2017-6-30
编辑:dpb 2017-7-1
But you've got
sweepData(sweepData<=threshold) = threshold;
in here that will change sweepData if there's any value in there that satisfies the condition of less than; only if there are values that are precisely equal to the threshold already would they be unchanged.
---> *here*
display(sum(sweepData))%%%%%%%%%%%%%%%%%%%%%%
---> *to here*
display(sum(staticSweepData))%%%%%%%%%%%%%%%%%%%%%%
Then you display the previously saved data prior to making the above change and display it in comparison to the new set.
Do this at a breakpoint before and after the above test --
sum(sweepData==threshold)
and it'll tell you how many were substituted.
You could also search for the locations that satisfy the condition and compare their initial value to the threshold, sum that difference and reproduce the difference between the first and second sums...
  3 个评论
dpb
dpb 2017-6-30
"I didn't think it changed the actual array..."
It's "logical addressing", one of the most powerful features of Matlab. It's no different than writing
x(1:3)=threshold;
as far as result which clearly is an assignment; the only difference is the index vector is a vector of logical and the locations in the vector that are true by position are those that are addressed; the false locations are left unchanged.
It doesn't appear the problem regarding the symptoms regarding magnitudes has anything to do with this; that has to be something in the collection process that we have no data for.
Good luck...at least there isn't something truly mysterious going on with this particular issue! :)

请先登录,再进行评论。

更多回答(1 个)

Jan
Jan 2017-6-30
编辑:Jan 2017-6-30
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 个评论
Veronica yep
Veronica yep 2017-6-30
Okay so the real problem hear is that the instrument I'm measuring from sometimes stops working and the data is not updated correctly, and the percentage of 'on' time of each frequency of the band tends toward either 100% or 0% depending on whether they are over or under the threshold. When this error begins, I pause and check the sum of the sweepData, but it says undefined function or variable, so the whole thing is screwing up and I have no idea why! Such is life
Jan
Jan 2017-6-30
编辑:Jan 2017-6-30
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Whos 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by