问题
I am using meshm
to plot densities.
How do I calculate the center point for each of the bins? I want to associate the data in m with the centerpoints I have looked at the source code of meshm
and believe the solution will be a modified version of meshm
that returns the latitude and longitudes of each bin's center point.
meshm
calls the function meshgrat
which returns the latitude and longitude points of the mesh that will be plotted by surfacem
. The problem is that the lat and lon matrices are not the same size as m. I need to match the latitude and longitude points with the density data in m I believe I need to scale the data based on GRATSIZE a variable in meshgrat
.
NOTE: meshm is part of the Matlab Mapping Toolbox
NOTE NOTE: This is a follow-up question to Determine distance from coastline in Matlab
回答1:
You can get the edges of the mesh using MESHGRAT, which is the function called by meshm
when it makes the grid for binning.
%# create the mesh that is used by meshm
[latgrat,longrat] = meshgrat(m,termaplegend);
%# find the latitudes of the center points
latPts = (latgrat(1:end-1,1:end-1) + latgrat(2:end,1:end-1))/2;
%# find the longitudes of the center points
lonPts = (longrat(1:end-1,1:end-1) + longrat(1:end-1,2:end))/2;
The center of the bin in 2nd row, 5th col is [latPts(2,5),lonPts(2,5)]
.
回答2:
Within meshm
just modify the inputs to meshgrat
:
[lat,lon] = meshgrat(Z, R, gratsize); % original
[lat, lon] = meshgrat(Z,R); % modification
By default, gratsize = []
which in meshgrat will return the default graticule size of 50 X 100. By not passing in gratsize, the graticule is set to the same size as Z.
来源:https://stackoverflow.com/questions/3680621/determine-center-of-bins-when-using-meshm