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: Mike Miller
Subject: Re: Check if the environment is Octave or Matlab
Date: Fri, 10 Apr 2020 12:21:09 -0700

On Fri, Apr 10, 2020 at 14:32:21 +0200, José Luis García Pallero wrote:
> Hello,
> 
> Sometimes I need to check if a function or script is running in Octave
> or Matlab. Usually I make the check as
> 
> if exist('OCTAVE_VERSION')
>     octave = 1;
> else
>     octave = 0;
> end
> 
> Is this the FASTEST way to check the environment or is there any other
> method more suitable?

The user manual has a suggestion that follows the same lines:

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

As the manual shows, if you are assigning a variable anyway, avoid the
if-else:

    octave = (exist('OCTAVE_VERSION', 'builtin') == 5);

and as others have suggested, you could make that persistent and/or
global, depending on your needs.

Cheers,

-- 
mike

Attachment: signature.asc
Description: PGP signature


reply via email to

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