Average data along z
조회 수: 7 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
채택된 답변
Walter Roberson
2018년 10월 5일
편집: Walter Roberson
2018년 10월 5일
[uxy, ~, uidx] = unique([x(:), y(:)], 'rows');
avgv = accumarray(uidx, v(:), [], @mean);
output = [uxy, avgv];
댓글 수: 2
Walter Roberson
2018년 10월 5일
The above can be used for scattered points where there are not necessarily the same number of z for each x/y combination.
추가 답변 (1개)
jonas
2018년 10월 5일
mean(A,3)
댓글 수: 2
Walter Roberson
2018년 10월 5일
This can be useful, but does depend upon the points being gridded, with an equal number of z points for each (x,y) pair.
jonas
2018년 10월 5일
Ah yes, that's how I interpret 3D to 2D, but in hindsight I agree that OP is probably looking for your solution.
참고 항목
카테고리
Help Center 및 File Exchange에서 Discrete Data Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!