Convert gridded data to coordinate matrix

4 views (last 30 days)
Kai
Kai on 21 Aug 2018
Commented: Kai on 21 Aug 2018
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.

Accepted Answer

Julie
Julie on 21 Aug 2018
coord=repmat(1:11,11,1);
XYZmat=cat(3,X(coord),Y(coord'),M);
  4 Comments
Julie
Julie on 21 Aug 2018
Xtemp=X(coord);
Ytemp=Y(coord');
XYZmat=[Xtemp(:)';Ytemp(:)';M(:)'];

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!