The Math Forum



Search All of the Math Forum:

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


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

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   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
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"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.



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

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.