help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Check if the environment is Octave or Matlab


From: Nicholas Jankowski
Subject: Re: Check if the environment is Octave or Matlab
Date: Fri, 10 Apr 2020 15:50:56 -0400

> I think you misread that response.  I believe what Philip was saying that he put that code (starting with if exist(...)) in a file called isOctave.  I don't believe there is a built in function to do what you're asking.  The caveat was that, if you're looking for the FASTEST way, it would evoke some function call overhead than putting that code directly into your code, so it would be relatively slower than putting it inline.

is this something you're looking to do repeatedly?   if so the Octave manual and wiki offer the following suggestion to use a persistent variable with is_octave so you only have to call exist once:

-----------------
%%
%% Return: true if the environment is Octave.
%%
function retval = isOctave
  persistent cacheval;  % speeds up repeated calls

  if isempty (cacheval)
    cacheval = (exist ("OCTAVE_VERSION", "builtin") > 0);
  end

  retval = cacheval;
end
-------------------

https://octave.org/doc/interpreter/How-to-Distinguish-Between-Octave-and-Matlab.html
https://wiki.octave.org/Compatibility

reply via email to

[Prev in Thread] Current Thread [Next in Thread]