Convert gridded data to coordinate matrix

조회 수: 2 (최근 30일)
Kai
Kai 2018년 8월 21일
댓글: Kai 2018년 8월 21일
Hello, I was wondering if there is some Matlab command to convert gridded data to a coordinate matrix. For instance, I have
X = -1:0.2:1;
Y = -1:0.2:1;
M = rand(11,11);
and M(i,j) represents the z-value of (X(i),Y(j)) (which is random in here, but usually this will be the value under some function F(x,y) of course). Now I would like to convert M to a matrix C of size 11*11 times 3, each row giving the coordinates of one grid point specified by M. I could run some for-loops and define the rows one by one, but I was wondering if there is some specific Matlab command for this.

채택된 답변

Julie
Julie 2018년 8월 21일
coord=repmat(1:11,11,1);
XYZmat=cat(3,X(coord),Y(coord'),M);
  댓글 수: 4
Julie
Julie 2018년 8월 21일
Xtemp=X(coord);
Ytemp=Y(coord');
XYZmat=[Xtemp(:)';Ytemp(:)';M(:)'];
Kai
Kai 2018년 8월 21일
Perfect, thank you!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by