help-octave
[Top][All Lists]
Advanced

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

Re: numel(foo{:}) - feature or bug ?


From: Ben Abbott
Subject: Re: numel(foo{:}) - feature or bug ?
Date: Fri, 05 Aug 2011 08:56:48 -0400

On Aug 5, 2011, at 7:23 AM, Sergei Steshenko wrote:

> Hello,
> 
> first here is screen output of 'help numel' in octave-3.4.2:
> 
> "
> octave:1> help numel
> `numel' is a built-in function
> 
> -- Built-in Function:  numel (A)
> -- Built-in Function:  numel (A, IDX1, IDX2, ...)
>     Return the number of elements in the object A.  Optionally, if
>     indices IDX1, IDX2, ... are supplied, return the number of
>     elements that would result from the indexing
> 
>           A(IDX1, IDX2, ...)
> 
>     This method is also called when an object appears as lvalue with
>     cs-list indexing, i.e., `object{...}' or `object(...).field'.
> 
>     See also: size

In case there is some confusion about what fun(foo{:}) does ...

        fun(foo{:})

is the same as ...

        fun (foo{1}, fun{2}, ..., fun{end})

Thus ...

>> foo{1} = "a";
>> foo{2} = "ab";
>> foo{3} = "abc";
>> foo{4} = [1 2 3 4; 5 6 7 8; 9 10 11 12];
>> 
>> numel (foo{:})
ans =  72
>> numel (foo{1})
ans =  1
>> numel (foo{1}, foo{2}, foo{3}, foo{4})
ans =  72

foo{2:4} constitute 2, 3, 3*4 indices. Thus the total number if implied indices 
is 2*3*3*4 = 72

Ben


reply via email to

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