필터 지우기
필터 지우기

Is there a simpler way to find the index of the first non NaN value in a vector?

조회 수: 118 (최근 30일)
temp = X;
temp(~isnan(temp)) = 1;
temp(isnan(temp)) = 0;
temp = find(temp);
first_non_NaN_index_of_X = temp(1);

채택된 답변

OCDER
OCDER 2018년 7월 3일
편집: OCDER 2018년 7월 3일
X= [NaN NaN 1 2 3 4 5];
first_non_NaN_index_of_X = find(~isnan(X), 1);
  댓글 수: 2
Mr M.
Mr M. 2018년 7월 3일
Thanks, and what about last non NaN? I have to use fliplr, or not necessary?
OCDER
OCDER 2018년 7월 3일
No need as the find function has a last one search feature.
last_non_NaN_index_of_X = find(~isnan(X), 1, 'last')

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by