对于这类事情,我一直使用 setappdata/getappdata 方法。这是您所做工作的一般分类。当您创建图形时,给它们一个这样的标签:
figure( ..., 'Tag', 'info_gui', ... ); % tag name is up to you
figure( ..., 'Tag', 'other_gui', ... ); % tag name is up to you
任何时候您需要一个或其他数字的句柄,只需像这样调用 findobj
info_gui_handle = findobj('tag','info_gui');
other_gui_handle = findobj('tag','other_gui');
好的,现在让我们在 info_gui 中存储一些示例数据,我们稍后会更新
info_gui_data.x = 1;
info_gui_data.y = 1;
setappdata( info_gui_handle, 'info_gui_data', info_gui_data);
设置好数字后,您可以执行以下操作:
% First you get a handle to the info gui figure
info_gui_handle = findobj('tag','info_gui');
% Next you get the appdata thats stored in this figure. In this example
% I have previously stored a struct variable called
% 'info_gui_data' inside the appdata of the info_gui
info_gui_data = getappdata(info_gui_handle ,'info_gui_data');
% Make your changes whatever they are. Here I am modifying variables x
% and y that are stored in the struct info_gui_data
info_gui_data.x = 2;
info_gui_data.y = 2;
% Now that I've made changes to the local variable info_gui_data I can
% now store it back into the info gui's appdata.
setappdata(info_gui_handle ,'info_gui_data',info_gui_data);
我喜欢将我所有的图形应用数据存储在一个巨大的结构中。似乎更容易跟踪,但这取决于您。希望这可以帮助 :)