Distinguishing Octave from Matlab

David Bateman David.Bateman at motorola.com
Fri Feb 15 04:32:34 CST 2008


Søren Hauberg wrote:
> fre, 15 02 2008 kl. 11:02 +0100, skrev David Bateman:
>   
>> A function that does what you want is
>>
>> function ret = isoctave ()
>>   persistent isoct
>>   if (isempty (isoct))
>>      isoct = exist('OCTAVE_VERSION') ~= 0;
>>   end
>>   ret = isoct;
>> end
>>     
> Is the 'exist' call really so slow that you need to use a persistent
> variable? Wouldn't it be just as good to use
>
> function ret = isoctave ()
>   ret = (exist('OCTAVE_VERSION') ~= 0);
> endfunction
>
> ?
>
>   
In this case yes.. The reason is that "OCTAVE_VERSION" is a builtin in
recent versions of Octave and was previously a variable, therefore we
can either check both "var" and "builtin" resulting in the need two
tests, or as we don't care about the speed of the first call, just check
all possibilities for the type of OCTAVE_VERSION. This allows this
function to identify all versions of Octave I know of.. However, the use
of exist twice will be slower, and a generic exist call is even slower
as it searches the loadpath for possible functions, thus causing disk
activity. So its better to use a persistent in this case.

D.




-- 
David Bateman                                David.Bateman at motorola.com
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph) 
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob) 
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax) 

The information contained in this communication has been classified as: 

[x] General Business Information 
[ ] Motorola Internal Use Only 
[ ] Motorola Confidential Proprietary



More information about the Help-octave mailing list