Determining if a variable exists within a GUI

2 visualizaciones (últimos 30 días)
Jenna McCoy
Jenna McCoy el 22 de Abr. de 2018
Respondida: Walter Roberson el 22 de Abr. de 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

Respuesta aceptada

Walter Roberson
Walter Roberson el 22 de Abr. de 2018
delete(findobj(gca, 'type', 'line'))

Más respuestas (0)

Categorías

Más información sobre App Building en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by