How to get information about toggle state of checkboxes in GUI?

2 views (last 30 days)
Hello,
currently i'm trying to build a GUI with GUIDE. The aim is to have an Array or Matrix 2x8 (8 checkboxes in figure) which contain the Information about the toggle state of the respective Checkbox. The gui function is saved seperately as an m.file an executed by its Name in main code. The following is part of the function created with GUIDE.
if true
% --- Outputs from this function are returned to the command line.
function varargout = Auswahlbox_Werte_Zustaende_OutputFcn(hObject, ~, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
%
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject2, ~, handles)
v=get(hObject2,'Value')
%
% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject3, ~, handles)
gb=get(hObject3,'Value')
%
% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject4, ~, handles)
%
ped_d=get(hObject4,'Value')
%
% --- Executes on button press in checkbox5.
function checkbox5_Callback(hObject5, ~, handles)
%
p=get(hObject5,'Value')
%
% --- Executes on button press in checkbox6.
function checkbox6_Callback(hObject6, ~, handles)
%
s=get(hObject6,'Value')
%
% --- Executes on button press in checkbox7.
function checkbox7_Callback(hObject7, ~, handles)
ped_s=get(hObject7,'Value')
%
% --- Executes on button press in checkbox8.
function checkbox8_Callback(hObject8, ~, handles)
K1=get(hObject8,'Value')
%
% --- Executes on button press in checkbox9.
function checkbox9_Callback(hObject9, ~, handles)
K3=get(hObject9,'Value')
%
% Hint: get(hObject,'Value') returns toggle state of checkbox9
%
% --- Executes during object deletion, before destroying properties.
function pushbutton2_CreateFcn(hObject, eventdata, handles)
%
function pushbutton2_DeleteFcn(hObject, eventdata, handles)
%
function pushbutton2_Callback(hObject, eventdata, handles)
%
close(gcf);
%
end
One failure note I get is:
Undefined function or variable 'checkbox2_CreateFcn'.
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in Auswahlbox_Werte_Zustaende (line 42) gui_mainfcn(gui_State, varargin{:});
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)Auswahlbox_Werte_Zustaende('checkbox2_CreateFcn',hObject,eventdata,guidata(hObject))
Thanks in advance!

Answers (1)

Adam
Adam on 5 Oct 2017
You can fix that error by locating the checkbox in GUIDE, opening the Property Inspector for it and finding the 'CreateFcn' field and deleting what is in it.
That is not anything to do with the toggle state of the checkbox though so I don't know if that is just part of your question, but you didn't ask anything about toggle state despite it being in the title!
  3 Comments
Adam
Adam on 5 Oct 2017
The variables are defined in a function so they have function scope. Generally there is no need to have variables appear in the base workspace from a GUI because they should be used within the GUI itself.
You can use
doc assignin
to do this, but it is ugly and I have never used it. It is generally a symptom of bad design to need to be doing that.
laboratoryassist
laboratoryassist on 5 Oct 2017
I'm afraid I'm still a beginner and need to realize it this way.
You helped me a lot. Thanks.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!