'How to call a function in Matlab GUI?

Im new in matlab, Im trying to call a function inside a matlab GUI but I keep getting an error. Can you please help.

 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


Solution 1:[1]

You have to get your data from the gui data. You can retrieve these data from the function "guidata".

In fact what happens, is that you define a variable in the "main function" but you cannot access this one.

What you should do is to add this variable in the handles in the "GUI_OpeningFcn" function:

Note_Vector = [ ];
output = [ ];
Counter = 0
for i=1:Total_num
    Note_Vector = [Note_Vector Note+Shift];
end
handles.Note_Vector = Note_Vector;
handles.GLoutput = output; %handles.output is already the handle of your GUI, don't change it.
handles.counter=counter;
handles.Total_num=Total_num;
(...)
guidata(hObject, handles);

then you can either retrieve these data in PushMe_Callback by simply writing handles.Note_Vector OR you can retrieve them by doing the following in Get_Length function handles = guidata(handle). In that case you'll have to put in input the handle of your GUI

Get_Length(Note_Vector,output,Counter,Total_num,handles.output)

I let you check the matlab help file concerning guidata() if you want more information.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Wli