MATLAB: Problem using GUIDE

callbackguide

Hello. i am a new user of matlab and i am trying to use the GUIDE to create an interface to an existing program.
the program works perfectly on its own but when i try to use the interface to get the variables i run into
??? Undefined function or variable "EQ_PROT".
any help will be appreciated. Any more info you need i will try to answer asap
Thank you very much

Best Answer

The FAQ won't open? That is odd. But here is a copy of what it says:
How can I share data between callback functions in my GUI(s)?Edit
Unlike custom functions that you write, the callback functions take the predetermined input variables (hObject, eventdata, handles) so it's not clear how you can pass in other variables that you need to. There are several techniques you can use to share data between callback functions in your GUI. Which approach is easiest depends on whether you are creating your GUI using GUIDE to design the layout (GUIDE-based GUIs) or whether you are calling FIGURE, AXES, UICONTROL, etc. directly (programmatic GUIs.)
The main techniques are:
Using the handles structure. You can dynamically add on new members to the handles structure that contain your variables that you want to pass in. Unlike global variables, which expose the variables only where you put the global statement, attaching to the handles structure and passing handles will share all the variables you have attached to the handles structure. This could expose variables to your function that you did not need or want exposed. Since variables passed in to MATLAB functions are "pass by value" and not "pass by reference" if you change any of the variables, you are only changing the local copy. If you change any of the variables attached as members of the handle structure, and you want to retain these changed values in the calling function, you will have to return the handles structure as an output of your function, and accept it in your calling function, or else use the guidata() function. Otherwise changes you make to the handles structure variables are only local and will not survive once the function has returned.
% Add a brand new variable on to the handles structure.
handles.myNewVariable = 42;
Creating your callback functions as nested functions inside the main GUI function. The function must be truly nested with the main function's "end" statement and not merely listed as another separate, independent function just defined in the m-file. (There is a difference.)
Storing data in a property [often the UserData property] of a component in the GUI and retrieving it when needed. For example
set(handles.button1, 'UserData', myString).
Storing data in the application workspace using the SETAPPDATA and GETAPPDATA functions.
% Do this to save variables to your figure's workspace.

% handles.GUIHandle is the "Tag" property of your main GUI figure.
% Double-click figure to bring up the "Property Inspector" in GUIDE.
setappdata(handles.GUIHandle, 'yourVariable', yourVariable)
% Do this to retrieve variables from your figure's workspace.
yourVariable = getappdata(handles.GUIHandle , 'yourVariable')
% Do this to remove what you saved from your figure's workspace.
rmappdata(handles.GUIHandle, 'yourVariable')
Writing the data out to a file, such as a mat file with the save function, and then having the called function read in that mat file.
% Do this to save variables to your figure's workspace.
% yourVariable could be a single variable that is a structure
% with a bunch of variables as members of the structure
% if you wish. That can be convenient because then there
% is only one variable to save.
save(fullMATFileName, 'yourVariable')
% Do this to retrieve the variable.
storedStructure = load(fullMATFileName);
yourVariable = storedStructure.yourVariable;
Use the assignin() function.
% Send the variable myGUIVariable from the GUIs workspace
% to a variable called myBaseVariable in the "base" workspace.
assignin('base', 'myBaseVariable', myGUIVariable);
% They could both be the same name if you wish.
assignin('base', 'myVariable', myVariable);
Sharing between multiple GUIs. If the "main" GUI calls other GUIs, then the best way to do it is by passing variables in via the input argument list, and accepting output variables via the output argument list. The output argument of GUI2 can then be sent into GUI3. So someplace in GUI1 (like the callback function of the "Go!" button of GUI1), you'd have this
[out2a out2b out2c] = gui2(in2a, in2b, in2c, in2d);
[out3a out3b] = gui3(out2a, out2b);
or something along those lines. The arguments can be extracted out of the varargin cell array of your opening code for the GUI, for example in the GUI's "OpeningFcn" function if you used GUIDE. Once they are in your opening function, then they can be shared amongst the other functions in the GUI with the methods mentioned earlier in this section. This method will not let GUI1 control GUI2 and GUI3's parameters "live" - they can be changed only when calling the GUIs. To have GUI1 control GUI2 when GUI2 is already running, you can use the assignin() function.
Official Documentation. The documentation contains instructions for using these techniques to share data between callbacks in a GUIDE-based GUI ( <http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f5-998197.html>) and in a programmatic GUIs ( <http://www.mathworks.com/access/helpdesk/help/techdoc/creating_guis/f13-998197.html>).