passing variables from gui to another m file

1 次查看(过去 30 天)
hi
i have a gui interface whereby there is a drop down list to choose which data set you want. i have another my file that is dependent on the users choice of the dataset. how do i link the data from gui to another my file.
should i create a function
mydata=getdatamatirx(handles)
mydata = handles.data

采纳的回答

Sean de Wolski
Sean de Wolski 2012-2-24
FAQ This should help.
  5 个评论
eliza
eliza 2012-2-27
what i am trying to do is:
from the gui the proper matrix data is extracted and then have to link that data to another m file. i am having trouble extracting the matrix to the other m file.
is there away to do this without having to define the matrices as global variables?
Sean de Wolski
Sean de Wolski 2012-2-27
Yes, did you read the FAQ? use setappdata to store it and getappdata to retrieve it.
■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')
You could also set to the root directory, i.e. 0., that way stuff is stored even after you close the GUI.
%Set
setappdata(0,'myStuff',stuff);
%Extract
mystuff = getappdata(0,'mystuff')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by