How to identify the position in which a value is NaN

7 ビュー (過去 30 日間)
Alfredo Scigliani
Alfredo Scigliani 2022 年 4 月 20 日
コメント済み: Voss 2022 年 4 月 20 日
I want to be able to identify the position in which a value is NaN
If I have:
x = [1 NaN 3 4 5 NaN 7 8 9 10]
In which the second and sixt position are NaN
something that gives me an answer = [ 2 , 6 ] is what I am looking for.
I usually use the "find" such as find(x==3) would return = 3 (because it is at the third position), but now I want to apply it for NaN
Not sure how that could be done, wonder if anybody can help me. Thanks in advance!

採用された回答

Voss
Voss 2022 年 4 月 20 日
編集済み: Voss 2022 年 4 月 20 日
You can use the isnan function:
x = [1 NaN 3 4 5 NaN 7 8 9 10];
find(isnan(x))
ans = 1×2
2 6
  2 件のコメント
Alfredo Scigliani
Alfredo Scigliani 2022 年 4 月 20 日
Yes! Thank you so much!
Voss
Voss 2022 年 4 月 20 日
You're welcome!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by