Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

how to write callback for check box

Asked by rafi abdul

rafi abdul (view profile)

on 4 Feb 2013

hi how to write code to remove plot by unchecking check box.

function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
data=get(handles.uitable1,'data');
plot(data(:,1),data(:,2));

as per above callback i am able to plot when checkbox is checked, please guide me how to write code for unchecking checkbox so that plot gets deleted

0 Comments

rafi abdul

rafi abdul (view profile)

Products

No products are associated with this question.

2 Answers

Answer by Walter Roberson

Walter Roberson (view profile)

on 4 Feb 2013
Accepted answer
if get(hObject, 'Value')
  handles.plot = plot(data(:,1),data(:,2));
else
  delete(handles.plot);
  handles.plot = [];
end
guidata(hObject, handles);

0 Comments

Walter Roberson

Walter Roberson (view profile)

Answer by rafi abdul

rafi abdul (view profile)

on 4 Feb 2013
Edited by Azzi Abdelmalek

Azzi Abdelmalek (view profile)

on 4 Feb 2013

thanks for reply walter.it was very helpful.actually i have 3 plots in my code .when 3 plots are displayed in figure i want to select one plot and zoom in x and y direction.can you guide me how to proceed further .

function checkbox1_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox1
data=get(handles.uitable1,'data');
if get(hObject, 'Value') 
handles.plot1 = plot(data(:,1),data(:,2));
else  delete(handles.plot1);
handles.plot1 = [];
endguidata(hObject, handles);
% --- Executes on button press in checkbox2.function checkbox2_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA) 
% Hint: get(hObject,'Value') returns toggle state of checkbox2 
data=get(handles.uitable1,'data');
if get(hObject, 'Value') 
handles.plot2 = plot(data(:,1),data(:,3));
else  delete(handles.plot2); 
handles.plot2 = [];
endguidata(hObject, handles);
% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject    handle to checkbox3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox3
data=get(handles.uitable1,'data');
if get(hObject, 'Value') 
handles.plot3 = plot(data(:,1),data(:,4));
else 
delete(handles.plot3); 
handles.plot3 = [];endguidata(hObject, handles);

1 Comment

Jan Simon

Jan Simon (view profile)

on 4 Feb 2013

Please learn how to format code.

rafi abdul

rafi abdul (view profile)

Contact us