Help when trying to exclude matrix values while indexing!

조회 수: 10 (최근 30일)
SKYLAR SCHUTTER
SKYLAR SCHUTTER 2020년 3월 10일
댓글: SKYLAR SCHUTTER 2020년 3월 10일
I am trying to figure out how to index a matrix but exclude certain values. Specifically I have
y=grid.y;
latitudes = [-90 90];
I=find(y>=min(lat) & y<=max(lat));
II=find(y<=min(lat) & y>=max(lat));
The first find works (I), the second (II) does not and returns a NaN value. help?
  댓글 수: 1
Ameer Hamza
Ameer Hamza 2020년 3월 10일
Can you attach a sample dataset so we can try to replicate the issue?

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

답변 (1개)

Guillaume
Guillaume 2020년 3월 10일
"the second (II) does not and returns a NaN value"
Firstly, find never returns NaN. It can return an empty array, this is not the same thing at all as NaN.
I wouldn't be surprised that your second expression returns an empty array. numbers that are both smaller than a minimum while at the same time being larger than a maximum are ... very rare! You 2nd expression can be rewritten as:
II = find(y <= -90 & y >= 90);
which clearly is not going to be satisfied often.
In fact, only NaN numbers can satisfy this expression. So your find will return the indices of the NaN values in y or empty if there are no NaN.
  댓글 수: 1
SKYLAR SCHUTTER
SKYLAR SCHUTTER 2020년 3월 10일
Thank you for your comment! I think my confusion comes from misunderstanding the fundamentals of the "find" function. I was trying to use it to generate an index that represented the columns of my matrix but I see know that that was flawed. Thank you for your help!

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by