Clear Filters
Clear Filters

How to check and unchecked box using plot in GUI

2 views (last 30 days)
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 Comment
Adam
Adam on 11 Feb 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.

Sign in to comment.

Accepted Answer

Kevin Phung
Kevin Phung on 11 Feb 2019
Edited: Kevin Phung on 11 Feb 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)

More Answers (0)

Categories

Find more on Graphics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!