[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How can a script tell if it's running on Octave or Matlab?

From: John W. Eaton
Subject: How can a script tell if it's running on Octave or Matlab?
Date: Fri, 25 Sep 1998 10:43:28 -0500 (CDT)

On 25-Sep-1998, address@hidden <address@hidden> wrote:

| I want to make a script run on both Octave and Matlab.  Mostly
| this involves simply using the common subset of the language,
| e.g., only % comments, no short circuit logical operators, etc.
| I do want to make a plot or two, and I think that is best done
| with conditional code.  So the question is, what conditional can
| I use to choose?

You could look look for the built-in constant __OCTAVE_VERSION__,
which seems unlikely to be set in a user's Matlab startup file.
I think something like

  is_octave = exist ('__OCTAVE_VERSION__') ~= 0;

should do the trick.

If you think someone might actually define a variable with this name
in their Matlab startup file, you could try an operation that will
only work in Octave.  Perhaps omething like
  is_octave = eval ('isstr ("Matlab chokes on double quotes");', '0');

would work (until Matlab supports double quotes, anyway).  Maybe it's
best to put the test in an M-file so that you can easily change it for
all your scripts if needed.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]