Determining if a variable exists within a GUI

2 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2018-4-22
delete(findobj(gca, 'type', 'line'))

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 App Building 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by