MATLAB: Making a function to restructure matrix of coordinates

MATLABmatlab functionmatrixmatrix arraymatrix manipulation

I have a 36×3 matrix of data in a double, where the three columns represent x, y, and z coordinates. I'm trying to make two functions. The first will restructure the matrix so that it becomes a 6×6 data set, where the column and row numbers represent the x and y values and the cells represent the z values. The second reverses this, and converts the 6×6 back into the original 36×3. I've looked a bit into using the reshape function, but I dont know how to incorporate the values of the rows and columns. Any help is appreciated. Thanks.

Best Answer

Z=reshape(xyz(:,3),6,6); %6x6 format
and then to revert back,
[X,Y]=ndgrid(1:6);
xyz=[X(:),Y(:),Z(:)]; %36x3 format
Related Question