0

I am new to MATLAB GUI building and I am trying to learn how to pass data between two GUIs. My question is how to call a function in the main GUI from a sub GUI.

For example:

In the main GUI, I am getting the values from two text box from their respective callbacks as such:

handles.A= str2double(get(handles.textbox1,'string'));  

guidata(hObject,handles)

handles.B = str2double(get(handles.textbox2,'string'));   

guidata(hObject, handles)

then in addition to the above, I have a third function that does addition as such:

function addition(handles)    

C= handles.A + handles.B

The third function however is being accessed from the sub GUI through a button push as follows:

function pushbutton1_Callback(hObject, eventdata, handles)   

main_gui('addition');

The error I am getting is not enough input arguments in the line C = handles.A + handles.B, but I don't know why I am getting this error. Can anyone help me?

Justin Morgan - On strike
  • 30,035
  • 12
  • 80
  • 104
Ali P
  • 519
  • 6
  • 21

1 Answers1

0

You're calling addition without any input arguments. One way pass data between your GUIs is to pass handles.a and handles.b to the sub GUI as input arguments and then use them as input arguments to addition.

At the top of the sub GUI opening function (subGUI_OpeningFCN) add the lines:

handles.a = varargin{1};
handles.b = varargin{2};

Change the sub GUI function pushbutton1_Callback to:

main_gui('addition', handles.a, handles.b);

In main_gui change addition to accept two input arguments:

addition(handles.a,handles.b)

Then, also in main_gui,call subGUI like this:

subGUI(handles.a,handles.b);

Note that addition could be defined in a separate m file instead of in the main GUI.

Molly
  • 13,240
  • 4
  • 44
  • 45