フィルターのクリア

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 Center および File Exchange2-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