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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by