フィルターのクリア

Getting handles of lines and deleting last 2 line plots

5 ビュー (過去 30 日間)
Jason
Jason 2020 年 2 月 14 日
編集済み: Jason 2020 年 2 月 14 日
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

採用された回答

Steven Lord
Steven Lord 2020 年 2 月 14 日
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 件のコメント
Jason
Jason 2020 年 2 月 14 日
編集済み: Jason 2020 年 2 月 14 日
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)
?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by