I am trying to mask netcdf (unable to attach as zip file exceeds 5MB) based on a Mississippi river basin shapefile(attached) using inpolygon. But I get this following error:
Arrays have incompatible sizes for this operation.
Error in inpolygon (line 76)
mask = (x >= min(xv)) & (x <= max(xv)) & (y>=min(yv)) & (y<=max(yv));
Error in plot_soilice (line 10)
[in,on] = inpolygon(lon,lat,C.X,C.Y);
Below is the code I used:
C = shaperead('\MRB_Shapefile\mrb.shp');
lat=ncread('\Noah.monthlymean.01.nc','lat');
lon=ncread('\Noah.monthlymean.01.nc','lon');
SMC=ncread('\\Noah.monthlymean.01.nc','SMC');
SMC_n = squeeze(SMC(:,1,:));
[in,on] = inpolygon(lon,lat,C.X,C.Y);
numel(lat(~in)) + numel(lat(in));
mymap=pcolor(lon,lat,in2);
I assume this will happen with any shapefile as the lat lon grids of shapefile will be different from the netcdf lat/lon grids. Eventually, the matrices of lat/lon from shapefile and netcdf lat/lon matrice will always be different. So, I am looking for a generic solution that can be applied for any shapefile and any netcdf file meaning different matrix sizes of lat lon. Does anybody have any suggestions for this problem and a generic solution?
Any suggestions or help is appreciated.
Thanks