开发者

Problem with two fig files

I have 2 fig files. One开发者_StackOverflow fig (say fig2) is called from the other fig (say fig1). My problem is when fig2 is open, user should not be able to click on or edit fields in fig1. Once the user closes the fig 2, he/she can edit on fig 1. How can I do this?


You can set your fig2's WindowStyle property to 'modal'. This will prevent ALL the other windows from being accessible while fig2 is open - not just fig1.

If you just want fig1 to be inaccessible, then use the mechanism explained in http://undocumentedmatlab.com/blog/disable-entire-figure-window/


I would like to add a bit to Yair's answer. In all of the GUI's I have worked on, I usually want to halt code execution as well. Using only the Modal option, the code is not halted. Below I have a quick example of the use of uiwait and modal options Yair (and his link) touched on.

Note that if you are trying to disable only the one figure and continue code execution, Yair's link might be your best option.

Hope this helps!

%% 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')
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜