Clear Filters
Clear Filters

how to write callback for check box

17 views (last 30 days)
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

Accepted Answer

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

More Answers (1)

rafi abdul
rafi abdul on 4 Feb 2013
Edited: Azzi Abdelmalek 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);

Categories

Find more on Programming Utilities 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!