Difference between MATLAB's numel and length functions

后端 未结 3 1723
有刺的猬
有刺的猬 2021-01-01 08:46

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 ar

3条回答
  •  借酒劲吻你
    2021-01-01 09:32

    For a 1-by-N array, they are essentially the same. For a multidimensional array M, they can give different results:

    • numel(M) is equivalent to prod(size(M)).
    • length(M) is equivalent to max(size(M)). If M is empty (i.e. any dimension is 0), then length(M) is 0.

提交回复
热议问题