display checkbox value in editfield

2 Ansichten (letzte 30 Tage)
acegi bdegi
acegi bdegi am 20 Dez. 2017
Kommentiert: acegi bdegi am 2 Jan. 2018
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.

Antworten (1)

Image Analyst
Image Analyst am 20 Dez. 2017
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 Kommentare
acegi bdegi
acegi bdegi am 21 Dez. 2017
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 am 2 Jan. 2018
I found it.
if app.CheckboxIN.Value
D = 1;
else
D = 0;
end
app.numericfield.Value = D; % Display 1 or 0 in numeric field

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by