Matlab / GNU Octave "isinteractive" function

It’s useful to know if the Matlab or GNU Octave GUI is open for a number of use cases, including

  • pause for each group of a large set of plots–only if user is there to look at them, otherwise save to disk and close thereafter.
  • increase (or decrease) verbosity of print statements or if console output is logged, depending on if it batch mode or not.

We don’t use the Matlab batchStartupOptionUsed as it doesn’t detect the -nodesktop case often used for unattended batch processing. Save this code to isinteractive.m for your project.

function isinter = isinteractive()
%% tell if the program is being run interactively or not.

if isoctave
  isinter = isguirunning;
  % matlab, this test doesn't work for Octave
  % don't use batchStartupOptionUsed as it neglects the "-nodesktop" case
  isinter = usejava('desktop');