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

72 visualizzazioni (ultimi 30 giorni)
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!

Risposta accettata

Cris LaPierre
Cris LaPierre il 13 Giu 2023
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 Commenti
Cris LaPierre
Cris LaPierre il 13 Giu 2023
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.

Accedi per commentare.

Più risposte (1)

dpb
dpb il 13 Giu 2023
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 Commento
Margaux
Margaux il 13 Giu 2023
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...

Accedi per commentare.

Categorie

Scopri di più su Develop Apps Using App Designer in Help Center e File Exchange

Prodotti


Release

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by