Estimate length with out NaN's

115 ビュー (過去 30 日間)
George
George 2015 年 3 月 11 日
コメント済み: Star Strider 2015 年 3 月 11 日
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)));
  2 件のコメント
George
George 2015 年 3 月 11 日
Thank you very much, just what I needed !
Star Strider
Star Strider 2015 年 3 月 11 日
My pleasure!

サインインしてコメントする。

その他の回答 (1 件)

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2015 年 3 月 11 日
If x is your vector.
YourLength = length(x) - sum(isnan(x))

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by