Next: , Up: FAQ - Frequently asked Questions


37.3.1 How to distinguish between Octave and Matlab?

Octave and matlab are very similar, but handle Java slightly different. Therefore it may be necessary to detect the environment and use the appropriate functions. The following function can be used to detect the environment. Due to the persistent variable it can be called repeatedly without a heavy performance hit.

Example:

     %%
     %% Return: true if the environment is Octave.
     %%
     function ret = isOctave
       persistent retval;  % speeds up repeated calls
     
       if isempty(retval)
         retval = (exist('Octave_VERSION','builtin') > 0);
       end
     
       ret = retval;
     end