Geospatial mapping: map one state from data from the continental US

Hi,
I'm using Matlab 2014b. I have a gridded data for the entire US in a matrix (621 x 1405). I am calling this matrix 'data'. I made a georasterref using the following code.
R = georasterref();
R.LatitudeLimits=[ 24.062499 49.9375];
R.LongitudeLimits=[-125.0208333 -66.4792];
R.RasterSize=[621 1405]
I can plot the continental US using this code.
geoshow(data, R, 'DisplayType','Surface')
I just want to plot the data that are contained with the CA boarders. I am pretty sure I need to use the filterm function. I have tried multiple different approaches. Some examples of my attempts are below.
Example 1
[latout,lonout,indx] = filterm(californiahi.Lat,californiahi.Lon,data,R)
Example 2
Lat=24.062499:.0416668:49.9375;
Long=-125.0208333:.0416668:-66.4792;
[flat,flon,index]=filterm(Lat,Long,californiahi,data,'allowed');
Any guidance on how to plot only the data in the CA boarders would be very much appreciated.
THANK YOU in advance. Julie

 Accepted Answer

Use inpolygon. If you have lat/lon data given by ( latdata, londata) and California outline given by ( latCA, lonCA),
in = inpolygon(londata,latdata,lonCA,latCA);
will return a matrix the same size as latdata. It will have ones for any data within California's borders, zeros otherwise. Then you can use plotm(latdata(in),londata(in) or pcolorm(latdata(in),londata(in),Zdata(in) or what-have-you.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!