Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: numel or length, which is better?
Replies: 7   Last Post: Dec 14, 2014 9:29 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
dpb

Posts: 8,296
Registered: 6/7/07
Re: numel or length, which is better?
Posted: Apr 16, 2013 3:39 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 4/16/2013 2:16 PM, dpb wrote:
> On 4/16/2013 2:03 PM, Hesham Ismail wrote:
...

>> length calculate the number of column whereas numel calculate the number
>> of element

> ...
>
> Not necessarily...
>

...

> As noted in earlier response LENGTH() is max(size(x)) for any x whereas
> NUMEL() is prod(size(x))
>
> If one is interested in rows or columns (and often are) then have to ask
> for the size of the pertinent dimension to be certain....


And to belabor the point but to drive it home...

>> D=rand(2,3,5);
>> length(D)

ans =
5
>> max(size(D))
ans =
5
>> size(D)
ans =
2 3 5
>>

I've used utility functions on occasion for nrows and ncols as syntactic
sugar--they're trivial to write, of course--

function nr=nrows(x)
% N = nrows(A) returns the number of rows, N, in array A.

nr=size(x,1);

function nc=ncols(x)
% N = ncols(A) returns the number of cols, N, in array A.

nc=size(x,2);

--






Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.