How to make pcolor plot from three vector

8 次查看(过去 30 天)
I have matrix A of size 3X250, where in the value of altitude corresponds to longitude and latitude
A= [latitude, longitude, altitude]
I want to plot pcolor for latitude and longitude with bin/grid size of 5 degree, where in bin should contain mean data of altitude within the 5 degree bin and should reflect in the colorbar. The plot should look somewhat like the following
Thanks for your inputs in advance

采纳的回答

Kelly Kearney
Kelly Kearney 2017-9-6
You can calculate the bin averages pretty quickly using discretize and accumarray:
Some sample data:
npt = 10000;
A = [rand(npt,1)*180-90 rand(npt,1)*360-180 rand(npt,1)];
5-degree bins:
latbin = -90:5:90;
lonbin = -180:5:180;
nlat = length(latbin);
nlon = length(lonbin);
Use discretize to figure out which latitude and longitude bin each point falls into, then convert the row/column indices into a single array index.
ilat = discretize(A(:,1), latbin);
ilon = discretize(A(:,2), lonbin);
idx = sub2ind([nlat nlon], ilat, ilon);
Use accumarray to average the values assigned to each index, then reshape to a grid:
altg = accumarray(idx, A(:,3), [nlat*nlon 1], @(x) mean(x), NaN);
altg = reshape(altg, nlat, nlon);
Finally, plot:
pcolor(lonbin, latbin, altg);
  1 个评论
Aristo
Aristo 2018-1-12
I wanted to apply 'shading interp' for the above code, If one of them is Nan, this point is not coloreated since the interpolation is between 4 vertices, what is the other alternative for it

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Geographic Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by