# How to calculate the binned average at the center of each X and Y grid points?

4 visualizzazioni (ultimi 30 giorni)
Leon il 29 Set 2021
Commentato: Leon il 29 Set 2021
I have a grid like the below and a 3-column data: x, y, z.
[X Y] = ndgrid([-179.5:179.5], [-89.5:89.5]);
How do I calculate the average within each bins? The average needs to be with latitude/longitude at the center of each lat/lon grid box (e.g. lat/lon 0.5/0.5 for the mean of all values within the box 0.0 to 1.0 latitude including the southernmost point 0.0 but not the northernmost point 1.0"
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Matt J il 29 Set 2021
[N,~,~,binX,binY] = histcounts2(x,y,([-179.5:179.5], [-89.5:89.5]);
zBinned = accumarray([binX,binY],z(:))./N;
##### 1 CommentoMostra -1 commenti meno recentiNascondi -1 commenti meno recenti
Leon il 29 Set 2021
Many thanks for the solution!

Accedi per commentare.

### Categorie

Scopri di più su Geometric Geodesy in Help Center e File Exchange

R2021a

### Community Treasure Hunt

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

Start Hunting!

Translated by