Input and Output GUI using Guide
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dina Ashraf
el 21 de Mayo de 2020
Comentada: Geoff Hayes
el 25 de Mayo de 2020
Hello everyone,
I created a GUI to take around 12 inputs from the user then I took those inputs and stored them in variables.
Some of those variables created are based on the user's selection of a radiobutton, for example if a user selects radiobutton x I store the value 3 in a variable called m.
Example: % --- Executes on button press in radiobutton16.
function radiobutton16_Callback(hObject, eventdata, handles)
m=0
Now I would like to write a code to process those variables and perform operations on them. However every time I do that I get errors like this one:
Undefined function or variable 'a0'.
Error in Input_GUI_2>Input_GUI_2_OpeningFcn (line 59)
z=a0-b0
Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});
Error in Input_GUI_2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Even though a0 is a variable created later on in the code: a0=get(handles.edit13,'string')
Can anybody please tell me what to do now?
Thanks a lot in advance.
0 comentarios
Respuesta aceptada
Geoff Hayes
el 21 de Mayo de 2020
Dina - when you create a variable like m within your callback function, it is local variable to that function and is not accessible by any other callbacks. That would explain why you are getting errors like Undefined function or variable 'a0'. If you would like to share data between callbacks then you could use the handles structure to store that data. For example,
Example: % --- Executes on button press in radiobutton16.
function radiobutton16_Callback(hObject, eventdata, handles)
handles.m = 0;
guidata(hObject, handles); % <-- this is needed to update handles with the new field
Your other callbacks would then check to see if the m field exists in handles and then access it in the usual way. For example,
function someother_Callback(hObject, eventdata, handles)
if isfield(handles, 'm')
data = handles.m;
% do something with data
end
Note that if your variable just represents the state of a radio button, then you could just check (from your other callbacks) what the state of that button is using the handles structure (whose fields are handles to the controls).
3 comentarios
Geoff Hayes
el 25 de Mayo de 2020
Dina - try creating a function that will take the user data as input parameters and then have it return whatever you want to display in the text (or other) control of the GUI.
Más respuestas (0)
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!