help-octave
[Top][All Lists]
Advanced

[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: ldoolitt Subject: How can a script tell if it's running on Octave or Matlab? Date: Fri, 25 Sep 1998 11:22:09 -0400 (EDT)

```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?

One way might be to use the version, and guess that major version
4 or 5 is Matlab, major version 2 is Octave.  Along the way, I found
a difference in the default behavior of the str2num function.  Will
this be stable?

I ran the following on Matlab and  Octave:
v=version
vn=str2num(version)
running_under_octave=length(vn)==0
va=str2num(strrep(version,'.',' '))
running_under_octave=va(1)<4

Matlab (extraneous vertical space deleted):
v = 5.1.0.421
vn = 5.1000         0    0.4210
running_under_octave = 0
va = 5     1     0   421
running_under_octave = 0

Octave (somewhat less extraneous vertical space deleted):
v = 2.0.13
vn = [](0x0)
running_under_octave = 1
va = 2   0  13
running_under_octave = 1

Comments?  Better ideas?  I'm all ears!

- Larry Doolittle   <address@hidden>

```

reply via email to

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