问题
Suppose that I have a button in a window that when I click on it a new window will appear. I call this window (with the name of My_New_Window
) with this syntax:
My_New_Window();
I want to insert some values to this new window from main window. I know that I can use setappdata
or getappdata
for this purpose but Is there another way to this? For example like this syntax:
My_New_Window(Values);
Another question. When we use setappdata
or getappdata
, where MATLAB stores this data? In the RAM or Hard drive?
回答1:
Yes, you can use
My_New_Window(Values);
For example, in GUIDE, whatever parameters you pass to your GUI, you can handle in theOpeningFcn
using itsvarargin
input. Simply assignvarargin
to yourhandles
structure and useguidata(hObject, handles);
Regarding
setappdata
- according to this book the data is stored inside an "object". Since objects reside in memory, it is safe to assume that it is indeed kept in RAM.
回答2:
You can store data in the GUI UserData property:
set(handletoFigure,'UserData',Values);
when you open the other GUI you retrieve the info:
Values = get(handletoFigure,'UserData);
Is there a reason why you don't want to use setappdata/getappdata?
As for your 2nd question I don't know sorry. I guess it's the RAM though
来源:https://stackoverflow.com/questions/25017784/importing-values-from-one-window-to-another-in-matlab-gui