MATLAB: How to rearrange values in a matrix

matrix manipulation

Hello, I have a large matrix with 3 columns(x,y,and z) and I want to rearrange the values inside this matrix. Example:
*Initial matrix
x y z
1 1 5
1 2 6
1 3 7
2 1 8
2 2 9
2 3 2
*Final matrix My goal is to rearrange the values of the matrix in this form
y
x 1 2 3
1 5 6 7 <-z values
2 8 9 2

Best Answer

There are a few elegant ways to do this. I would use accumarray
data = [
1 1 5
1 2 6
1 3 7
2 1 8
2 2 9
2 3 2];
V = accumarray(data(:,[1 2]),data(:,3))
Now V does not have the index values, but you already know them:
rr = 1:size(V,1) %row
cc = 1:size(V,2) %column
So I would just keep them separate.