how to write callback for check box

6 vues (au cours des 30 derniers jours)
rafi abdul
rafi abdul le 4 Fév 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

Réponse acceptée

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

Plus de réponses (1)

rafi abdul
rafi abdul le 4 Fév 2013
Modifié(e) : Azzi Abdelmalek le 4 Fév 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 commentaire
Jan
Jan le 4 Fév 2013
Please learn how to format code.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by