How do i use 3 checkboxes to plot graphs on same axes and be able to uncheck any particular box in guide

1 次查看(过去 30 天)
I am trying to use 3 checkboxes to create 3 plots on same axis.When checkbox1 is checked,only its plot is shown and when its unchecked there is no plot.Similarly when I check or uncheck the other checkboxes too,it should do the same.Also ,if i check checkbox 2 and 3,it should show both plots for it. I was able to check and uncheck checkboxes separately. But the problem occurs,when I have all three boxes checked(all 3 plots on the axes) and then try to uncheck them,they don't work like they should.I am not able to understand the problem.
Here is the relevant code:
*% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
% hObject handle to checkbox1
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data
axes(handles.axes1);
if get(hObject, 'Value')
x=[22;33;44];
y=[10,22,33];
handles.plot = plot(x,y,'r');
hold on
else
delete(handles.plot);
handles.plot = [];
end
guidata(hObject, handles);
and similar code for checkbox 2 and 3. Any help will be appreciated.

回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by