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.

  • I'm not sure this is a question that is appropriate here... – J. M. Dec 1 '11 at 12:56
  • I am sure. It's not. – Manos Dec 1 '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. – Jyrki Lahtonen Dec 1 '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. – Willie Wong Dec 1 '11 at 13:33
  • Sorry I didn't know where to post it. Thanks for your help. – pirad Dec 2 '11 at 6:21

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


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.