How to call a function inside a Matlab GUI

2 visualizaciones (últimos 30 días)
Eric Letsolo
Eric Letsolo el 9 de Nov. de 2012
function PushMe_Callback(hObject, eventdata, handles)
set(handles.output_line,'String','I Got here');
Get_Length(Note_Vector,output,Counter,Total_num)
%------------------------------------------------------------
function Get_Length(Note_Vector,output,Counter,Total_num)
output = [ ];
while (1)
T = Total_num - Counter;
for j=1:T
[xml_input]=Get_Note(Note_Vector(j));
output = [output xml_input];
end
end
  5 comentarios
Milos
Milos el 9 de Nov. de 2012
Are the variables Note_Vector,output,Counter,Total_num in the GUI workspace?
Eric Letsolo
Eric Letsolo el 9 de Nov. de 2012
I think thats what Im struggling with, to put them in the GUI workspace. I tried to define them as global variables in the opening function. This is how i did it but it still returns an error:-
function AMNR_OpeningFcn(hObject, eventdata, handles, varargin) global d; d = [ ]; global Note_Vector; Note_Vector = [ ];

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 9 de Nov. de 2012
Well apparently Note_Vector is not in scope inside the PushMe_Callback() function so that when PushMe_Callback() goes to call Get_Length(Note_Vector,output,Counter,Total_num) it does not know what Note_Vector is. And it probably doesn't know what output,Counter,Total_num are either. When you set a breakpoint there, and then type in those variables into the command window, what does it say? Or you can look in the workspace panel to see the variables that are in the local workspace of your PushMe_Callback() function. Actually this is all just basic debugging - do you know how to debug: set breakpoints, examine variables, step through code, etc.? Also are you aware of scope, which means that every function has its own private set of variables and that a function won't see any other functions variables unless you take special care to make it see them. All functions don't automatically see every other functions internal variables. So if you defined Note_Vector somewhere, like in the OpeningFcn() function where you put startup code, it doesn't mean that every callback function in your m-file will automatically see those variables internal to OpeningFcn. A custom function you wrote won't even see variables you attach to the handles structure unless you pass the handles structure into your custom function. And you better pass it back out if you make any changes to it or those changes will be lost once the function exits. Why don't you check out the FAQ: http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.28s.29.3F
  1 comentario
Eric Letsolo
Eric Letsolo el 10 de Nov. de 2012
I've debugged the code and tried many approaches. When I run the main function from mscript, it puts the variables in the workspace which I can access them in GUI using "evalin". Now the problem is how do I put the variables in the workspace without physically running the main mscript file?

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by