Effacer les filtres
Effacer les filtres

How to make pcolor plot from three vector

8 vues (au cours des 30 derniers jours)
Aristo
Aristo le 6 Sep 2017
Commenté : Aristo le 12 Jan 2018
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

Réponse acceptée

Kelly Kearney
Kelly Kearney le 6 Sep 2017
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 commentaire
Aristo
Aristo le 12 Jan 2018
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

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Geographic Plots dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by