필터 지우기
필터 지우기

How can I delete an xline/plot from a plot without deleting the other ones on the graph? (I am using checkbox)

조회 수: 59 (최근 30일)
Good morning,
I am currently using MatLab App Designer to create an app and I am using axes for my plot and checkboxes on the side to make plot/xlines appear. I have a function for each one of my checkboxes so that if i check one of them, that specific line will be on the graph but not the other. If I check multiple boxes, I will have my eslected lines on the plot but once I turn one of my checkboxes off, it deletes all of my line, even if my other checkboxes are still checked. here is an example of one of my checkboxes:
function FT4CBValueChanged(app, event)
value = app.FT40CB.Value;
p40 = plot(app.CoVPlot, [40 40], [0 500], "Color", "r", "LineWidth", 2);
if value == 1
str40 = "CoV @ 40'" ;
plot(app.CoVPlot, p40)
text(app.CoVPlot, [40.5 40.5], [40 40], str40)
else
cla(app.CoVPlot)
yline(app.CoVPlot, 15, "b", "LineWidth", 2)
yline(app.CoVPlot, 10, "b", "LineWidth", 2)
end
end
To clear my line, I am using cla (i know it is to clear the axes, zhich is zhy all of my other plotted lines are disappearing, but that it the only thing that make me delete my lines from the plot).
Hopefully it makes sense!
Thank you for the help!

채택된 답변

Cris LaPierre
Cris LaPierre 2023년 6월 13일
Yes, cla clears everything on the axes. Instead, delete the handle to your line. See this answer: https://www.mathworks.com/matlabcentral/answers/21006-how-to-erase-a-line
To work, you will have to save your line handle as an app property. See here: https://www.mathworks.com/help/matlab/creating_guis/share-data-across-callbacks-in-app-designer.html
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2023년 6월 13일
I'm attaching a simple example. If you can plot the line, you can remove it using delete as long as you have captured the line object as an app property. See the attached app.
Margaux
Margaux 2023년 6월 13일
Ok yeah, I just forgot to name it in the properties, it works now. Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
dpb 2023년 6월 13일
You need to keep each line handle when it is plotted as a global app data variable for each CB that plots each line. Then the callback for the CB that is to unset that particular line uses that particular handle -- it could either delete the line completely or just toggle the 'Visible' property 'on','off' if the user can expect to turn it back on again...
  댓글 수: 1
Margaux
Margaux 2023년 6월 13일
Thank you for your answer! I have also tried that but it seems like even though the "visible" property is "off", we can still see the line...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by