Plotting variable from NetCDF file
Show older comments
Hello all,
I'm Student and work on my project but unfortunately, I faced a problem. I limit latitude and longitude of NetCDF using find<= but some part of it has been offside, I mean Some pixels are outside of the country. See the below figure: (the red line is country borders, and you'll see some pixel are outside)

I want to use inpolygon function in order to mask the country of interest. I want to eliminate all outside the country data and achive something like this picture below:

So I used this code below:
filename = 'tmin.1982.nc'
time = ncread(filename,'time'); %read time
lat = ncread(filename,'lat'); %reading latitude
lon = ncread(filename,'lon'); %reading longitude
tmin = ncread(filename,'tmin'); %reading the main variable precip=(lon*lat*time)
tmin_mean = mean(tmin, 3); %average of precip in all times
[x, y] = borders('Iran Islamic Republic of'); % study region
[lonG, latG] = ndgrid(lon, lat); %you might have to reverse these
in = inpolygon(lonG, latG, x, y);
inmask = repmat(in, 1, 1, size(tmin,3));
masked_tmin = tmin;
masked_tmin(~inmask) = nan;
mean_masked_tmin = mean(masked_tmin, 3, 'omitnan');
but after plot it using this code:
%plot
surf(lon, lat, mean_masked_tmin(:,:,:).'); view(2)
axis xy
%shading interp
cmocean 'rain' % rainy to dry colormap %from Climate data toolbox (Chad A. Greene)
xlabel longitude
ylabel latitude
hold on
borders('countries','color',rgb('dark gray'))
cmocean 'rain'
cb = colorbar;
cb.Label.String = 'Average Temperature';
xlabel longitude
ylabel latitude
I saw that it's far away from where it should be. I mean it must be in a yellow-highlighted region but it is far away (see figure below):

I don't know what the problem is.
I haven't any experience with this problem. here is size and other information that i'm screenshot them:

Accepted Answer
More Answers (0)
Categories
Find more on NetCDF 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!