Determining if a variable exists within a GUI

2 views (last 30 days)
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

Accepted Answer

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

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!