Help when trying to exclude matrix values while indexing!
Show older comments
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 Comment
Ameer Hamza
on 10 Mar 2020
Can you attach a sample dataset so we can try to replicate the issue?
Answers (1)
Guillaume
on 10 Mar 2020
"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 Comment
SKYLAR SCHUTTER
on 10 Mar 2020
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!