MATLAB的numel和长度的函数的区别 [英] Difference between MATLAB's numel and length functions

查看:230
本文介绍了MATLAB的numel和长度的函数的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道长度(X)收益 MAX(尺​​寸(X)) numel(x)的返回x的元素的总数,但它是由n个阵列对于1更好?不要紧,或者是他们在这种情况下可以互换?

I know that length(x) returns max(size(x)) and numel(x) returns the total number of elements of x, but which is better for a 1 by n array? Does it matter, or are they interchangeable in this case?

编辑:只是踢:

看起来他们是相同的性能明智的,直到你到达10万的元素。

Looks like they're the same performance-wise until you get to 100k elements.

推荐答案

在这种情况下,他们返回相同的,而且也没有区别。在性能来看,这取决于阵列在MATLAB内部工作。例如。如果有关于有多少个元素的阵列(无论形状)在metainformations,然后numel是尽可能快,而最大(大小(X))似乎需要更多的工作,以获得同样的事情(检索大小和然后找到那些之间的最大值)。我习惯使用 numel 在这种情况下,但性能的讲话(假设)分开,我会说他们是可以互换的。

In that case they return the same and there's no difference. In term of performance, it depends on the inner working of arrays in MATLAB. E.g. if there are metainformations about how many elements are in the array (no matter the shape), then numel is as fast as possible, while max(size(x)) seems to need more work to obtain the same thing (retrieving sizes, and then finding the max among those). I am used to use numel in that case, but performance speech (hypothetical) apart, I would say they are interchangeable.

这篇关于MATLAB的numel和长度的函数的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆