Determining if a variable exists within a GUI

2 Ansichten (letzte 30 Tage)
Jenna McCoy
Jenna McCoy am 22 Apr. 2018
Beantwortet: Walter Roberson am 22 Apr. 2018
I would like my code to be able to delete the previously drawn line in order to only show the plot itself. I've tried using exist to check if it exists, but it won't function due to the variable not existing until the first line has been drawn. It is within an anonymous function used within a GUI if that makes any difference in how it should work, and it is based on sliders for the values it plots.
function [] = launcher(~,~)
if exist(plotdata, 'var') ~= 0
delete(plotdata);
end
hold off;
axis manual;
axis ([0 10 0 10]);
hold on;
h = get(0,'UserData');
vel = get(h.sliderVelocity,'Value');
ang = get(h.sliderAngle,'Value');
points = 0;
set(h.labelEquation,'String', sprintf('Velocity: %.2f, Angle: %.2f',vel,ang));
set(h.pointsPossible,'String', sprintf('Total Points Possible: %.0f/10',points));
x2 = (vel/20)*cos(ang);
y2 = (vel/20)*sin(ang)+5;
plotdata = plot([0;x2], [y0;y2]);
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 22 Apr. 2018
delete(findobj(gca, 'type', 'line'))

Weitere Antworten (0)

Kategorien

Mehr zu App Building finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by