display checkbox value in editfield
1 回表示 (過去 30 日間)
古いコメントを表示
Using App Designer, I want to display the status of a checkbox in an edit field, using a button, but using my code it says that the value has to be numeric. As far as I know is checked = 1, unchecked = 0, which IS numeric. So far I have the following very simple code, where 'CheckboxIN' is the CheckBox and 'CheckboxOUT is the NumericEditField: (this is on the callback of the button)
D = app.CheckboxIN.Value;
app.CheckboxOUT.Value = D;
Is 'Value' the right command to get the status of the checkbox?
Both text editfield and text area doesn't work as well.
0 件のコメント
回答 (1 件)
Image Analyst
2017 年 12 月 20 日
Edit field (text boxes) take strings, NOT numbers. So in the checkbox callback (not the edit callback), do this
% --- Executes on button press in checkbox1.
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
checkboxValue = handles.checkbox1.Value;
handles.edit1.String = sprintf('The checkbox value = %d', checkboxValue);
% Update handles structure
guidata(hObject, handles);
See attached demo.
2 件のコメント
参考
カテゴリ
Help Center および File Exchange で Create Custom UI Components についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!