Conditional variables depending on whether Matlab or Octave is running the code

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.

pirad

Posted 2011-12-01T12:51:26.613

Reputation: 185

I'm not sure this is a question that is appropriate here... – None – 2011-12-01T12:56:19.507

I am sure. It's not. – None – 2011-12-01T13:00:20.953

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. – None – 2011-12-01T13:13:05.730

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. – None – 2011-12-01T13:33:32.380

Sorry I didn't know where to post it. Thanks for your help. – pirad – 2011-12-02T06:21:32.017

Answers

2

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

hfs

Posted 2011-12-01T12:51:26.613

Reputation: 338