display checkbox value in editfield

2 次查看(过去 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.

回答(1 个)

Image Analyst
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 个评论
acegi bdegi
acegi bdegi 2017-12-21
Your code looks more like it's used for GUIDE and not App designer. I should've told in my explanation (edited now), although I used it in the tags.
I am using a NumericEditField, but also tried a text edit field and a textbox to see if that works. I indeed expect the value to be numeric.
App Designer doesn't know the command 'handles'. The app.name.Value tho, works for example for numericfield to numericfield and from listbox to textfield, but not for checkbox to numeric field.
Explained:
a = app.listbox.Value;
app.textfield.Value = a; %shows the selected item of the listbox
b = app.numericfield1.Value;
app.numericfield2.Value = b; %shows the value of numericfield1
What I want is a '0' or a '1' displayed in the numericeditfield, depending on the status of the checkbox.
acegi bdegi
acegi bdegi 2018-1-2
I found it.
if app.CheckboxIN.Value
D = 1;
else
D = 0;
end
app.numericfield.Value = D; % Display 1 or 0 in numeric field

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by