How to check and unchecked box using plot in GUI

2 次查看(过去 30 天)
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 个评论
Adam
Adam 2019-2-11
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.

请先登录,再进行评论。

采纳的回答

Kevin Phung
Kevin Phung 2019-2-11
编辑:Kevin Phung 2019-2-11
"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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by