0

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
Fish123
  • 25
  • 1
  • 2
  • 6
  • what's the error message? At which line does your code crash? – memyself Nov 09 '12 at 13:21
  • it returns "undefined variable" then lists the first variable Note_Vector – Fish123 Nov 09 '12 at 14:51
  • It returns an error message:- Undefined function or variable 'Note_Vector'. Error in AMNR>PushMe_Callback (line 414) Get_Length(Note_Vector,output,Counter,Total_num) – Fish123 Nov 09 '12 at 14:59
  • you should define the variable `Note_Vector` then. – memyself Nov 09 '12 at 15:02
  • it is defined in the main function, here is the code %main function Note_Vector = [ ]; output = [ ]; Counter = 0; while (1) for i=1:Total_num % % % Note_Vector = [Note_Vector Note+Shift]; end end – Fish123 Nov 09 '12 at 15:23

1 Answers1

0

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.

hyamanieu
  • 1,055
  • 9
  • 25