필터 지우기
필터 지우기

Index of NaN Values

조회 수: 126 (최근 30일)
Tiago Dias
Tiago Dias 2018년 7월 23일
편집: Walter Roberson 2018년 7월 23일
Hello,
My objective is to know the index of NaN values per column.
y = [1,2;NaN,4;5,NaN;7,8;9,NaN]
idx = isnan(y)
for j = 1:m
for i = 1:n
if idx(i,j) == 1
idx_all(i,j) = i
end
end
end
I get a result of
idx_all = 0 0
2 0
0 3
0 0
0 5
I would like the result to be something like
idx = [2 3
0 5]
Because the 1st column has just one NaN on row 2, and the 2nd column has NaN for row 3 and 5.
Thanks.
  댓글 수: 2
jonas
jonas 2018년 7월 23일
Is it really necessary to save the indices in that form? You should read about the find function.
Tiago Dias
Tiago Dias 2018년 7월 23일
yeah, but i would like to eliminate the zeros as well.

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

채택된 답변

Walter Roberson
Walter Roberson 2018년 7월 23일
A loop is easiest.
nc = size(y,2);
idx = zeros(0, nc);
for C = 1 : nc
nidx = find(isnan(y(:,C)));
idx(1:length(nidx), C) = nidx;
end
  댓글 수: 1
Tiago Dias
Tiago Dias 2018년 7월 23일
Thanks !! :)

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by