Converting 3D data to 2D

조회 수: 1 (최근 30일)
Josh K
Josh K 2017년 12월 6일
댓글: Josh K 2017년 12월 6일
I have a 50x4 matrix with the columns being x, y, z, and a value. I want to average each x,y point through the z to convert my 3D data to a 2D.
  댓글 수: 2
Walter Roberson
Walter Roberson 2017년 12월 6일
Does your data form a regular grid, perhaps 5 x 5 x 2 ?
Or is it scattered data that is not on a grid?
Josh K
Josh K 2017년 12월 6일
It is a 5 x 5 x 2. I eventually want to read in much larger data sets but I want to get a working code for this size first.

댓글을 달려면 로그인하십시오.

채택된 답변

Jos (10584)
Jos (10584) 2017년 12월 6일
So, you want to ignore the z, and average the values for each specific combination of (x,y)?
xyzv = [1 1 1 10 ; 1 1 2 20 ; 1 2 3 30 ; 1 2 5 40 ; 2 2 4 10] % test data
[xy,~,j] = unique(xyzv(:,[1 2]),'rows') % unique combinations of (x,y)
xyv = [xy accumarray(j,xyzv(:,4),[size(xy,1),1],@mean)] % ignore z, average v
  댓글 수: 1
Josh K
Josh K 2017년 12월 6일
Works great! Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by