MATLAB: How to check and unchecked box using plot in GUI

unchecked box

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

Best Answer

"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)