Estimate length with out NaN's

123 visualizaciones (últimos 30 días)
George
George el 11 de Mzo. de 2015
Comentada: Star Strider el 11 de Mzo. de 2015
Hello
I use the length command to see the length of some of my variables, although they include NaN's inside by a previous script I used so as to fill them and compare them Is there a way to find the length of the data non-taking into account the NaN?
I tried nanlength , as you can use nanmean etc. although it does not like it
it gives me this error
Undefined function 'nanlength' for input arguments of type 'double'.
  1 comentario
Stephen23
Stephen23 el 11 de Mzo. de 2015
Editada: Stephen23 el 11 de Mzo. de 2015
Keep in mind that length does not give the number of elements in an array: for this you should use numel .

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 11 de Mzo. de 2015
This works:
nonan_len = length(x(~isnan(x)));
  2 comentarios
George
George el 11 de Mzo. de 2015
Thank you very much, just what I needed !
Star Strider
Star Strider el 11 de Mzo. de 2015
My pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

Giorgos Papakonstantinou
Giorgos Papakonstantinou el 11 de Mzo. de 2015
If x is your vector.
YourLength = length(x) - sum(isnan(x))

Categorías

Más información sobre Logical en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by