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

1 view (last 30 days)
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.

Answers (0)

Categories

Find more on 2-D and 3-D Plots 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!