Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
NCTM or The Math Forum.



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 (1byn, nby1)?
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.



