How to search for matching values
Show older comments
Hi. I have a table of latitude, longitude and shear wave anomaly (this is a text file). I would like to search this table for minimum shear wave anomaly within a given range of latitude and longitude (say 30 - 50 latitude, and 0 - 20 longitude). what would be the best way of doing this? i have tried using the intersect function but have problems and it doesn't return repeated values.
cheers alex
1 Comment
dpb
on 22 Oct 2013
Why not use min presuming this is an actual minimum?
To select subsets of the data it's convenient to use a helper function to make writing the conditions more concisely hiding the details --
ix=(iswithin(lat,30,50) & iswithin(long,0,20)); % indices that satisfy
[amin,idx]=min(dat(ix));
Above assumes a vector of lat and long; arrange the indices appropriately for your data structure. My utility function is...
function flg=iswithin(x,lo,hi)
% returns T for values within range of input
% SYNTAX:
% [log] = iswithin(x,lo,hi)
% returns T for x between lo and hi values, inclusive
flg= (x>=lo) & (x<=hi);
Simple and possible to write inline but it tends to make code much more legible to hide the logic operators...
Answers (0)
Categories
Find more on Tables 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!