MATLAB: Matlab Guide checkbox issue

checkboxesguide

I am new to matlab and got into an issue.
I have problem with checkboxes in my matlab gui.i am using 3 checkboxes to produce 3 different plots(graphs) on same axes .I want the checkboxes to work in a way that when i check all three of them,i get 3 pots on same graph.But then when i uncheck one say number3,i am now able to see only data for check boxes 1 and 2 . Similarly when i uncheck both 3 and 2,now i should see data of only check box 1. I am able to get data of all three boxes at one time,but when uncheck more than 1 box,the graph doesn't go away?
Any help will be appreciated.

Best Answer

Just have all three checkbox callbacks call the same function: CheckBoxChecked. Then in that function, clear everything and just plot the data you need to.
function checkbox1_Callback(hObject, eventdata, handles)
CheckBoxChecked(handles);
function checkbox2_Callback(hObject, eventdata, handles)
CheckBoxChecked(handles);
function checkbox3_Callback(hObject, eventdata, handles)
CheckBoxChecked(handles);
function CheckBoxChecked(handles)
cla('reset'); % Erase everything.
state1 = get(handles.checkbox1, 'value');
state2 = get(handles.checkbox2, 'value');
state3 = get(handles.checkbox3, 'value');
if state1
% Plot dataset 1
end
if state2
% Plot dataset 2
end
if state3
% Plot dataset 3
end