MATLAB: Average data along z

averagemultidimensional arrayrepeat values

I have data at given xyz points (i.e. locations). For each xy pair, there are multiple z values. I'd like to average the data along the z dimension. In other words, go from 3D+Value to 2D+AveragedValueAlongZ. Is there a fast way to do this (i.e. not needing loops)? Thanks in advance.

Best Answer

[uxy, ~, uidx] = unique([x(:), y(:)], 'rows');
avgv = accumarray(uidx, v(:), [], @mean);
output = [uxy, avgv];