Using push button to run function based on checkboxes
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (2 件)
Suha lasassmeh
2018 年 6 月 14 日
編集済み: Suha lasassmeh
2018 年 6 月 14 日
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 件のコメント
Rik
2018 年 4 月 17 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Function Creation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!