MATLAB: Transpose Translation Vector for addresses

transpose

Hi, I have G =
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1
-1 0 0 0 0 0 0 0 0 0 0 0 0
-1 0 0 0 0 0 0 0 5 5 5 0 0
-1 0 0 0 0 0 0 0 0 0 5 0 0
-1 0 0 0 0 0 0 0 0 0 5 0 0
and have translation vector for X….
X = zeros(nx,2);
[r, c] = find(G == 0); % Fill (X) with free nodes from (G)
X = [r, c]
X =
2 2
3 2
4 2
5 2
2 3
3 3
4 3
5 3
2 4
3 4
4 4
5 4
. .
. .
. .
which is reading columnswise.
I would like to sort in this order
X =
2 2
2 3
2 4
. .
3 2
3 3
3 4
. .
4 2
4 3
4 4
. .
5 2
5 3
5 4
I have tried
X(r,c) = reshape([X' 5], [], rows – 1)'
but get:
Error using horzcat Dimensions of matrices being concatenated are not consistent.

Best Answer

Y=sortrows(X)