How to iteratively add elements to a cell array without clearing previous elements?
16 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I am writing GUIDE code to identify peaks in a signal and return locations/magnitudes. I am trying to add an element to a cell array for every iteration through a different data trace (indexed by 'z'). PeakLoc and PeakMag are vectors returned from a peakfinding function external to the GUI code, and are different sizes for each new iteration.
[PeakLoc, PeakMag] = PeakFinder(%input data)
handles.PeakLoc{handles.z} = PeakLoc ;
handles.PeakMag{handles.z} = PeakMag ;
However, every addition clears previous entries to the cell array. For example, after processing the first trace (handles.z = 1):
assignin('base', 'PeakLoc', handles.PeakLoc) ;
PeakLoc =
1×1 cell array
{14×1 double}
While stepping through an additional trace (handles.z = 2) returns:
PeakLoc =
1×2 cell array
{0×0 double} {20×1 double}
The code should ideally return both the initial 14x1 vector as well as the new 20x1 vector. Any idea where this is going wrong?
0 Kommentare
Antworten (1)
Stephen23
am 15 Mär. 2019
Bearbeitet: Stephen23
am 15 Mär. 2019
I suspect that you forgot to actually store the handles data after you made changes to it. The handles structure inside the callback is a local copy, when you make any changes (e.g. adding fields or data) to it then those changes are not reflected in the original structure stored in the GUI figure. This means that all changes you make are simply discarded at the end of the callback function, unless you explicitly update the figure's copy with the local copy. You can use guidata to do that:
Simply add this at the end of any callback within which you change the handles data:
guidata(hobj,handles) % hobj is the first input to the callback.
2 Kommentare
Siehe auch
Kategorien
Mehr zu Scope Variables and Generate Names finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!