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: 6   Last Post: Apr 16, 2013 3:44 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,141
Registered: 6/7/07
Re: numel or length, which is better?
Posted: Apr 16, 2013 3:16 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 4/16/2013 2:03 PM, Hesham Ismail wrote:
> A=magic(4)
> length(A)
> numel(A)
>
> length calculate the number of column whereas numel calculate the number
> of element

...

Not necessarily...

>> B=rand(3,5);
>> length(B)

ans =
5
>> C=B';
>> length(B)

ans =
5
>> size(B)
ans =
3 5
>> size(C)
ans =
5 3
>>

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. Often (input
files for a good example) the number of rows is greater than the number
of columns, but it isn't always so.

Many years ago there was a bug in a ML function (INTERP1) that got
confused over the problem by internally making the assumption that was
so and would interpolate across multiple datasets instead of within if
there were more interpolants than the length of the interpolating tables
per variable.

--




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.