How to make pcolor plot from three vector
조회 수: 3 (최근 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
댓글 수: 0
채택된 답변
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);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Line Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!