使 MATLAB 编辑器或命令 window 以编程方式获取焦点

Making the MATLAB editor or command window grab focus programmatically

Matlab正在处理包含plot()命令的代码时,当plot()被处理时,Matlab将窃取window焦点。虽然很多人似乎觉得这种行为很烦人,但我发现它很有用,因为它可以作为提醒,告诉我何时处理了情节,并且我可以在 Matlab 是 运行 时做其他事情。

但是,我希望在计算完成时让 Matlab 窃取 window 焦点(Matlab 处于空闲状态),而不仅仅是当我包含 plot()figure()命令。

我发现 post 关于 禁用 plot() 的 window 窃取行为和 figure() (Inhibit Matlab Window Focus Stealing),但不是 添加 window 计算完成后的窃取行为。可以吗?

要使Matlab命令window获得焦点,可以在计算后加上commandwindow。来自documentation,

commandwindow opens the MATLAB® Command Window when it is closed, and selects the Command Window when it is open.

要使现有图形获得焦点,您可以添加 figure(h),其中 h 是图形句柄。来自documentation,

figure(h) does one of the following [...]

If h is the handle or the Number property value of an existing figure, then figure(h) makes that existing figure the current figure, makes it visible, and moves it on top of all other figures on the screen. The current figure is the target for graphics output.