How to call a function inside a Matlab GUI
Show older comments
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 Comments
David Barry
on 9 Nov 2012
What is the question? You need to give a bit more detail about what you are trying to do and why it isn't working. A vague title and a piece of code is not sufficient.
Eric Letsolo
on 9 Nov 2012
Edited: Eric Letsolo
on 9 Nov 2012
Eric Letsolo
on 9 Nov 2012
Milos
on 9 Nov 2012
Are the variables Note_Vector,output,Counter,Total_num in the GUI workspace?
Eric Letsolo
on 9 Nov 2012
Answers (1)
Image Analyst
on 9 Nov 2012
0 votes
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 Comment
Eric Letsolo
on 10 Nov 2012
Categories
Find more on Startup and Shutdown 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!