Getting handles of lines and deleting last 2 line plots

조회 수: 8 (최근 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 CenterFile Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by