How to call a function inside a Matlab GUI

조회 수: 4 (최근 30일)
Eric Letsolo
Eric Letsolo 2012년 11월 9일
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
Milos
Milos 2012년 11월 9일
Are the variables Note_Vector,output,Counter,Total_num in the GUI workspace?
Eric Letsolo
Eric Letsolo 2012년 11월 9일
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 = [ ];

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2012년 11월 9일
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
Eric Letsolo
Eric Letsolo 2012년 11월 10일
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?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by