Possible Duplicate:
How do I detect if I’m running MATLAB or Octave?

My code was designed using MATLAB and I still use it. However, if I try to run some parts of it using Octave, I get errors. For example, MATLAB code uses pause on which Octave doesn't.

Is there a way to check which programming environment is using the code? For example,

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.

有帮助吗?

解决方案

There is version function both in MATLAB and Octave. They return different values and MATLAB's version have some arguments, that are absent in Octave. Hope that helps.

其他提示

I think the best method is to have a sub function that checks this. The following snippet is probably the one that requires the minimum from the system. And with the persistent variable it can be called repeatedly without a heavy performance hit.

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

You can then use it easily in condition blocks. See that entry on the Octave wiki.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top