Ignore specific lines in Octave (but save them for Matlab)

Possible duplicate:
How to determine if Im MATLAB or Octave is working?

My code was developed using MATLAB, and I still use it. However, if I try to start some of its parts using Octave, I get errors. For example, MATLAB code uses pause on , which is not in Octave.

Is there a way to check which programming environment uses the code? For instance,

 if invoking_env == 'Matlab' % do this else % ok, so do this end 

I can use getenv('COMPUTERNAME') , but in this case the computer name is the same! Thanks.

+4
source share
2 answers

There is a version function in both MATLAB and Octave . They return different values, and the MATLAB version has some arguments that are missing from Octave. Hope this helps.

+6
source

I think the best way is to have a subfunction that tests this. The following snippet is probably one that requires a minimum of system. And with a constant variable, it can be called multiple times without a strong performance hit.

 function r = isoctave () persistent x; if (isempty (x)) x = exist ('OCTAVE_VERSION', 'builtin'); end r = x; end 

Then you can easily use it in condition blocks. See this entry in the Octave quiz.

0
source

All Articles