Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 Vinicius Queiroz Posts: 1 Registered: 12/14/14
Re: numel or length, which is better?
Posted: Dec 14, 2014 9:29 PM

"red" wrote in message <hkh0jh\$sdb\$1@fred.mathworks.com>...
> Which is correct/better usage for vectors (1-by-n, n-by-1)?

I know this is a pretty old thread, but since I didn't find anyone saying this, I think that it could be helpful:

I ran this line of code:
#>>a=[rand(100,1)];#

and then:

#>>tic; length(a); toc; tic; numel(a);toc;

Elapsed time is 0.000028 seconds.
Elapsed time is 0.000001 seconds.#

But I'm also aware that the first command usually takes longer to compute than the second, then, i did this:

#>>tic; numel(a);toc; tic; length(a); toc;

Elapsed time is 0.000003 seconds.
Elapsed time is 0.000018 seconds.#

Thus, it should be obvious that numel performs better, when a is a nx1 or 1xn vector.

Date Subject Author
2/5/10 red
2/5/10 Jos
4/16/13 hesham
4/16/13 dpb
4/16/13 Bruno Luong
4/16/13 dpb
4/16/13 dpb
12/14/14 Vinicius Queiroz