我有2个fig文件。一个图(比如fig2)从另一个图(比如fig1)调用。我的问题是当fig2打开时,用户不应该能够点击或编辑fig1中的字段。一旦用户关闭图2,他/她可以在图1上编辑。我该怎么做呢?
你可以设置你的fig2的WindowStyle属性为'modal'。这将防止在fig2打开时所有其他窗口被访问,而不仅仅是fig1。
如果你只是想让fig1不可访问,那么使用在http://undocumentedmatlab.com/blog/disable-entire-figure-window/
我想对Yair的回答补充一点。在我做过的所有GUI中,我通常也想停止代码执行。仅使用Modal选项,代码不会停止。下面我有一个使用uiwait和模态选项的快速示例Yair(和他的链接)谈到。
请注意,如果您试图只禁用一个数字并继续执行代码,Yair的链接可能是您的最佳选择。
希望这对你有帮助!
%% UIWait Example
clc
fig1 = figure('Name', 'fig1 - UIWAIT');
fig2 = figure('Name', 'fig2 - UIWAIT');
% Wait for figure 2 to close
disp('Note that the script execution halts, but other Matlab windows are still active')
uiwait(fig2)
disp('Script Execution continues on!')
disp('Figure 2 Closed!')
close(fig1);
disp('Figure 1 Closed')
%% Modal Example with uiwait
clc
fig1 = figure('Name', 'fig1');
disp('Note that the script execution halts, and All Matlab windows are blocked')
fig2 = figure('Name', 'fig2 - MODAL','WindowStyle', 'modal');
% Wait for figure 2 to close
uiwait(fig2)
disp('Figure 2 Closed!')
disp('Script Execution continues on!')
close(fig1);
disp('Figure 1 Closed')
%% Modal Example
clc
fig1 = figure('Name', 'fig1');
disp('Note that the script execution does not halt, and All Matlab windows are blocked')
fig2 = figure('Name', 'fig2 - MODAL','WindowStyle', 'modal');
% Wait for figure 2 to close
disp('Script Execution continues on!')
close(fig1);
disp('Figure 1 Closed')