How to make pcolor plot from three vector

조회 수: 3 (최근 30일)
Aristo
Aristo 2017년 9월 6일
댓글: Aristo 2018년 1월 12일
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에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by