Using push button to run function based on checkboxes
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a GUI that has a few check boxes (cell diameter, cell size, and centroid) and when I click a push button, I want it to calculate the values of just the boxes that were checked. I have the coding for each of these check boxes in their call back, but when I run the GUI and 'check' the boxes, it runs those functions immediately. How can I get them to appear just when the boxes are checked and after I have clicked the push buttom?
0 comentarios
Respuestas (2)
Suha lasassmeh
el 14 de Jun. de 2018
Editada: Suha lasassmeh
el 14 de Jun. de 2018
Don't write anything in the callbacks of the checkboxes. In the callback for your button write the code to execute the functions associated with each checkbox. See the example below:
% --- Execute on button press in PushButton
function PushButton_Callback(hObject, eventdata, handles)
% hObjet handle to PushButton
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cellDiameter = get(handles.cellDiametercheckbox,'Value');
cellSize = get(handles.cellSizecheckbox,'Value');
centroid = get(handles.centroidcheckbox, 'Value');
if cellDiameter
% write your function here for cell diameter
end
if cellSize
% write you function here for cell size
end
if centroid
% write your function here for centroid
end
% --- Execute on button press in cellDiametercheckbox.
function cellDiametercheckbox_Callback(hObject, eventdata, handles)
% hObject handle to cellDiametercheckbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Execute on button press in cellSizecheckbox.
function cellSizecheckbox_Callback(hObject, eventdata, handles)
% hObject handle to cellSizecheckbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Execute on button press in cellSizecheckbox.
function centroidcheckbox_Callback(hObject, eventdata, handles)
% hObject handle to centroidcheckbox (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
0 comentarios
Rik
el 17 de Abr. de 2018
Move the code to the callback for your button and include an if-statement around that code that queries the state (the Value property) of your checkbox.
0 comentarios
Ver también
Categorías
Más información sobre Function Creation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!