Delete line plot and plot new one on UI Axes
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
In appdesigner, I have values from (10 to 100) in a drop down menu. This will be used to create a line plot. If i click on a value in the drop down menu it should plot a line plot on the UI axes. However if another value is clicked, the old one should be deleted and the new value clicked should be the only one on the line. How do I do this please. I tried this but it not working.
Cons_Line = str2double(app.DCValueDropDown.Value);
for i = 1:length(app.DCValueDropDown.Items)
if isempty(get(groot,'CurrentFigure'))
delete(xline(app.UIAxes2,Cons_Line,'--r'))% this is a test to check whether there is an old line plot if yes it should be deleted
end
xline(app.UIAxes2,Cons_Line,'--r') % this sholud plot the new clicked value
end
4 Commenti
Geoff Hayes
il 27 Mag 2019
Daniel - I don't understand what the following code is attempting to do
if isempty(get(groot,'CurrentFigure'))
delete(xline(app.UIAxes2,Cons_Line,'--r'))% this is a test to check whether there is an old line plot if yes it should be deleted
end
The above seems to suggest if there is no figure (the isempty(get(groot,'CurrentFigure'))) then create a new x-line object and then delete it? Is that the intent? As for
delete(xline(app.UIAxes2,Cons_Line,'--r')))
aren't you just creating a new line object only to delete it again? How would that correspond to the existing one? Do you need to save the handle to the xline object that was created previously?
Risposte (1)
Geoff Hayes
il 27 Mag 2019
Daniel - I think I understand your intent...but does the code do what you are expecting it to do? Does get(groot,'CurrentFigure') actually check for the existence of a line or just for existence of the current figure? And won't the other line just create a new line object at the same location (x-coordinate) as the other new line that you are creating? Look at your code
Cons_Line = str2double(app.DCValueDropDown.Value);
for i = 1:length(app.DCValueDropDown.Items)
if isempty(get(groot,'CurrentFigure'))
delete(xline(app.UIAxes2,Cons_Line,'--r'))% this is a test to check whether there is an old line plot if yes it should be deleted
end
xline(app.UIAxes2,Cons_Line,'--r') % this sholud plot the new clicked value
end
You are using Cons_Line to create and delete a line
delete(xline(app.UIAxes2,Cons_Line,'--r'))
and then create again at the same position (!)
xline(app.UIAxes2,Cons_Line,'--r')
I recommend saving the handle (or vertical line object) from the previous time that you created the line and then delete that object before creating the new line.
0 Commenti
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!