Estimate length with out NaN's

123 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2015-3-11
编辑:Stephen23 2015-3-11
Keep in mind that length does not give the number of elements in an array: for this you should use numel .

请先登录,再进行评论。

采纳的回答

Star Strider
Star Strider 2015-3-11
This works:
nonan_len = length(x(~isnan(x)));

更多回答(1 个)

Giorgos Papakonstantinou
If x is your vector.
YourLength = length(x) - sum(isnan(x))

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by