Borrar filtros
Borrar filtros

Hi . what is the difference between numel() and length() of a given vector ?

144 visualizaciones (últimos 30 días)
what is the difference between numel() and length() of a given vector ?

Respuesta aceptada

KSSV
KSSV el 6 de Oct. de 2021
Editada: KSSV el 6 de Oct. de 2021
numel gives you total number of elements present in the array. i.e. it is product of result of size function.
A = rand(10,3) ;
numel(A)
ans = 30
size(A,1)*size(A,2)
ans = 30
length gives you maximum number of size or which ever is dominant along row and column.
A = rand(10,3) ;
length(A)
ans = 10
size(A,1)
ans = 10
%
B = A' ;
length(B)
ans = 10
size(B,2)
ans = 10
  2 comentarios
Stephen23
Stephen23 el 6 de Oct. de 2021
Editada: Stephen23 el 6 de Oct. de 2021
Indeed, LENGTH gives the size along the longest dimension, but not just rows or columns:
length(nan(2,3,4))
ans = 4
I have never seen anyone actually make use of this "feature".
KSSV
KSSV el 6 de Oct. de 2021
Editada: KSSV el 6 de Oct. de 2021
@Stephen yes...good point..forgot to consider multi dimensions.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by