3

When Matlab is processing code including the plot() command, Matlab will steal window focus, when plot() is processed. While many seem to find this behavior annoying, I find it useful as an alert telling me when the plot has been processed, and I can do something else while Matlab is running.

I would, however, like to have Matlab stealing window focus whenever calculations are done (Matlab being idle), and not just when I include the plot() or figure() command.

I have found a post about disabling the window stealing behavior of plot() and figure() (Inhibit Matlab Window Focus Stealing), but not on adding window stealing behavior when calculations are done. Can it be done?

Community
  • 1
  • 1
Mace
  • 1,259
  • 4
  • 16
  • 35
  • So basically what you want is to have some code that gives focus to a certain figure? – Dev-iL Sep 01 '15 at 12:17
  • Not necessarily a figure, just focus to the Matlab editor or command window, when Matlab is idle. That way I can work in another program while matlab is running, and be alerted when calculations are done. – Mace Sep 01 '15 at 12:24
  • For alerts you could also use `beep` etc. – Dev-iL Sep 01 '15 at 12:35

1 Answers1

3

To make Matlab command window get focus, you can add commandwindow after the calculations. From the documentation,

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

To make an existing figure get focus, you can add figure(h), where h is the figure handle. From the 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.

Community
  • 1
  • 1
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • The ´commandwindow´ does exactly what I want. Thanks! I will just have to include it in all codes. Isn't it possible to get this behavior through a Matlab setting once and for all codes? – Mace Sep 01 '15 at 12:29
  • It would be great to have Matlab automatically do that after each script or command. But I can't think of a way to achieve it – Luis Mendo Sep 01 '15 at 12:46
  • 2
    @Mace You could do `run('scriptname'); commandwindow` - not what you asked for, but probably better than editing all codes... – Dev-iL Sep 01 '15 at 15:13
  • 1
    @Dei-Il Or override the `run` command to call `scriptname` and then `commandwindow` – Luis Mendo Sep 01 '15 at 15:27