Average data along z

7 ビュー (過去 30 日間)
Alireza H.
Alireza H. 2018 年 10 月 5 日
編集済み: Alireza H. 2018 年 10 月 5 日
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.

採用された回答

Walter Roberson
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
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.
Alireza H.
Alireza H. 2018 年 10 月 5 日
編集済み: Alireza H. 2018 年 10 月 5 日
Thank you so much, Walter! This is exactly what I needed. My data was actually 4D: [ x y z Value] and I wanted 3D z-averaged: [x y AveragedValueAlongZ] but a minor change to your code did the job.

サインインしてコメントする。

その他の回答 (1 件)

jonas
jonas 2018 年 10 月 5 日
  2 件のコメント
Walter Roberson
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
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 ExchangeDiscrete Data Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by