MATLAB: Bin data into equally spaced intervals

.bin

I have a table with 3 columns (x coordinate, y coordinate, "corrisponding value") and approx. 5k rows (attacched). I'm looking to bin data into equally spaced intervals in x coordinate and y coordinate, then I want to take the average of "corrisponding value" on every bin. I was looking to accumarray function, seems perfect for what i'm looking for, but i can't implement the right code.
I have already readed this, but he has only x coordinate and y coordinate: https://it.mathworks.com/matlabcentral/answers/182552-binning-data-in-equally-spaced-intervals

Best Answer

Try this:
D = load('matlab.mat');
A91 = D.A91;
[Ux,~,ix] = uniquetol(A91(:,1), 5E-7);
[Uy,~,iy] = uniquetol(A91(:,2), 5E-4);
figure
stem3(A91(:,1), A91(:,2), A91(:,3), '.')
grid on
Means = accumarray([ix, iy], A91(:,3), [], @mean);
figure
bar3(Means.')
set(gca, 'XTickLabel',Ux, 'YTickLabel',Uy)
xlabel('X-Coordinate')
ylabel('Y-Coordinate')
zlabel('Mean of ‘Corresponding Value’')
producing this plot —
Bin data into equally spaced intervals - 2020 02 10.png
Experiment with the uniquetol tolerances to get different results.