3

I have written some code for Matlab/Octave. Basically, they have the same syntax and everything, but, for example, they have different functions for optimization (linprog/glpk,quadprog/qp).

I want to run the same code in both Matlab and Octave and this code suffers from needing different functions in each environment. Until now, I have a variable that tells the programm whether it is running on Matlab or on Octave, but I always have to set this variable manually.

Is there a way that a program can recognise in which environment it runs? So, I want a statement to set the variable x=1, if it is running on Octave and x=0 if it is running on Matlab.

jonsca
  • 4,077
  • 15
  • 35
  • 47
pirad
  • 185
  • 1
  • 1
  • 4
  • I'm not sure this is a question that is appropriate here... –  Dec 01 '11 at 12:56
  • I am sure. It's not. –  Dec 01 '11 at 13:00
  • I'm fairly sure that this question is in the wrong forum. My first guess would be that the answer depends on the OS, but I did most of my programming under DOS, so probably shouldn't comment. Migrate to SO? I will flag a moderator. –  Dec 01 '11 at 13:13
  • Ideally one should ask this at the MatLab or GNU Octave mailing lists/fora. But this is clearly off-topic. I'll migrate to SuperUser. As Jyrki pointed out, it may require making system calls and what not. –  Dec 01 '11 at 13:33
  • Sorry I didn't know where to post it. Thanks for your help. – pirad Dec 02 '11 at 06:21

1 Answers1

2

You could check whether Octave’s built-in variable OCTAVE_VERSION is set.

hfs
  • 398
  • 4
  • 11