views:

201

answers:

3

I need to write code that should run equally well in Octave and on MATLAB. Problem is that it needs to do some GUI stuff, which MATLAB and Octave handle completely differently.

Is there a way I can detect if I'm running MATLAB or Octave, in order to call the right function?

+3  A: 

In Matlab:

>> exist octave_config_info
ans =
     0

In Octave:

octave:3> exist octave_config_info
ans =  5
Peter
+5  A: 
isOctave = exist('OCTAVE_VERSION') ~= 0;
Amro
Good call, though it would be better encapsulated in a function.
Richie Cotton
+2  A: 

I would use, for example, the ver command, which yields:

in MATLAB:


MATLAB Version 7.7.0.471 (R2008b) Operating System: Linux 2.6.31-20-generic #57-Ubuntu SMP Mon Feb 8 09:05:19 UTC 2010 i686 Java VM Version: Java 1.6.0_04 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode


in Octave:


GNU Octave Version 3.0.5 GNU Octave License: GNU General Public License Operating System: Linux 2.6.31-20-generic #57-Ubuntu SMP Mon Feb 8 09:05:19 UTC 2010 i686


Another possibility is to use the license function.

jmbr

related questions