Input and Output GUI using Guide

23 visualizaciones (últimos 30 días)
Dina Ashraf
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.

Respuesta aceptada

Geoff Hayes
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
Dina Ashraf
Dina Ashraf el 22 de Mayo de 2020
Now that I have stored the user input data into variables. Do you know how I can use that data to build a program that performs calcalutions on it then display it as an output in another GUI window?
I have no idea where I can write the code without it messing with my GUI functions in the same .m file.
Pardon me I'm new to creating GUIs with guide.
Thank you so much.
Geoff Hayes
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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by