find function exceeds matrix dimensions?

조회 수: 5 (최근 30일)
Sarah Goldsmith
Sarah Goldsmith 2016년 7월 31일
댓글: Sarah Goldsmith 2016년 7월 31일
I'm trying to remove rows that contain Nans in two columns of a dataset. The dataset itself is 9895 x 26, but when I run the following code,
hh1 = hh1(~isnan(hh1(:, 19:20)),:);
it returns 'Index exceeds matrix dimensions' Further investigation revealed that when I run
find(~isnan(hh1(:, 19:20)))
it returns values ranging from 7037 to 19790, which is a problem because, as previously mentioned, the size of the dataset is only 9895 x 26.
Any idea what's going on?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2016년 7월 31일
편집: Azzi Abdelmalek 2016년 7월 31일
Depending on what you want, if the two columns should be equal to nan
hh1 = hh1(~all(isnan(hh1(:,19:20)),2),:)
%or if at least one column is equal to nan
hh1 = hh1(~any(isnan(hh1(:,19:20)),2),:)
  댓글 수: 1
Sarah Goldsmith
Sarah Goldsmith 2016년 7월 31일
Yes, thanks! The second one is what I was looking for!

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by