what's wrong with this code? polygon function
8 views (last 30 days)
Show older comments
I have a netcdf file containg data for a region over 4 country. I only want to have the data over specific country and not the rest of the region. I read so many document but still I cant do that and need help. here what's I've done yet:
filename= 'chirps-v2.0.monthly.nc'
time= ncread(filename,'time') %read time
lat = ncread(filename,'latitude'); %reading latitude
lon = ncread(filename,'longitude'); %reading longitude
precip = ncread(filename,'precip'); %reading the main variable precip=(lon*lat*time)
precip_mean= mean(precip, 3) %average of precip in all times
[x, y] = borders('Iran Islamic Republic of');
in = inpolygon(x,y,lon,lat) %!!!!! I GOT ERROR HERE !!!!! I write rest of code based on examples in MathWorks
precip_mean=precip_mean';
precip_mean(~in)=NaN;
surf(lon, lat, Mean_precip(:,:,:).'); view(2)
shading interp
colormap jet
hold on
pgon = polyshape (x,y,'simplify',false);
plot(pgon,'FaceColor','none','edgecolor','k','facealpha',1);
I want only precip that are in my study region's border.
4 Comments
Accepted Answer
Walter Roberson
on 4 Nov 2019
inpolygon requires the first two arguments (query locations) to be the same size as each other, and the polygon definition in the third and fourth argument to be vectors the same size as each other. You cannot define the boundaries with 360 lat and 720 long.
7 Comments
More Answers (0)
See Also
Categories
Find more on Geographic Plots 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!