Getting handles of lines and deleting last 2 line plots

8 vues (au cours des 30 derniers jours)
Jason
Jason le 14 Fév 2020
Modifié(e) : Jason le 14 Fév 2020
Hello. I am plotting some raw data from a spectrometer onto a UIAxes and a smoothed version of this data. So for each data curve, there are 2 plots.
I often have about 10 plots of raw data (and obviously 10 smoothed plots).
I want to be able to remove the last raw data (and its smoothed plot) and have tried the code below.
However, it doesn't seem to be doing what I want it to. When I first run this (from a pushbutton callback), it only removes one line and not 2.
I can't see my error.
try
h = findobj(app.UIAxes,'Type','line')
delete(h(2)); %Delete 2nd last line object
delete(h(1)); %Delete last line object
catch
end

Réponse acceptée

Steven Lord
Steven Lord le 14 Fév 2020
I wouldn't assume that the first two elements of the array returned by findobj were the last two lines created. I don't think the documentation for findobj promises that behavior. Instead I would create the lines with specific Tag property values that reflect the order or that you store the lines in order in an array that you store in a property of your app, so you can "push" and "pop" them off in order in your line deletion method.
  1 commentaire
Jason
Jason le 14 Fév 2020
Modifié(e) : Jason le 14 Fév 2020
Thanks Steven, could you expand on push and pop please. I don't see them as matlab functions.
Perhaps I could just do somethign like:
hlast(1)=plot(..my raw data)
hlast(2)=plot(..my smoothed version of raw data)
setappdata(0,'lastplots',hlast)
and then in my delete function
hlast=getappdata(0,'lastplots')
delete(hlast)
?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Object Properties dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by