delete(findobj(gca, 'type', 'line'))
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
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!