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

75 次查看(过去 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.

请先登录,再进行评论。

更多回答(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...

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by