Borrar filtros
Borrar filtros

How to check and unchecked box using plot in GUI

2 visualizaciones (últimos 30 días)
Gali Musa
Gali Musa el 11 de Feb. de 2019
Comentada: Adam el 11 de Feb. de 2019
I plotted trend lines after using various calculation. The plot includes 3 trends lines on x y plane and i used checkbox to shw another trend line calculation. I want to remove the last trend line using unchecked box.
the original plot has
axes(handles.axes1)
plot(x_clean,y_clean,'g'); hold on
plot(x,y,'r'); hold on
plot(xxx,yyy,'k'); hold on
xlevel('Hours (hr)')
ylevel('Corr. Power(MW)')
the other plot for checkbox is
axes(handles.axes1)
plot(xx,yy,'m'); hold on
xlevel('Hours (hr)');
ylevel('Corr. Power (MW)')
How can i unchecked this plot
Thank you
  1 comentario
Adam
Adam el 11 de Feb. de 2019
Simplest option is to keep hold of the handles when you plot them, e.g.
handles.hTrend1 = plot( x_clean,y_clean,'g');
...
guidata( hObject, handles )
Then you can simply use
delete( handles.hTrend1 )
in another function.

Iniciar sesión para comentar.

Respuesta aceptada

Kevin Phung
Kevin Phung el 11 de Feb. de 2019
Editada: Kevin Phung el 11 de Feb. de 2019
"How can i unchecked this plot "
axes(handles.axes1)
plot2 = plot(xx,yy,'m'); hold on
xlevel('Hours (hr)');
ylevel('Corr. Power (MW)')
set(plot2,'Tag','p2') % create a tag so that you can find this line elsewhere
Im assuming you have a callback function for checkboxes which essentially plot your trendlines.
You can set it like so:
plot2 = findobj(groot,'Tag','p2')
if CheckBoxHandle.Value == 0;
set(plot2,'Visible','off')
else %when value is 1 (checked)
set(plot2,'Visible','on')
end
*note: this assumes that your line was already plotted
However, if you're looking to just remove the line entirely then just do
delete(plot2)

Más respuestas (0)

Categorías

Más información sobre Graphics 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