MATLAB: Inserting missing rows in a matrix

inserting missing rows in a matrix

If I have a matrix like x = [1 1; 1 2; 2 1; 2 2; 2 3; 3 1; 3 2]
x =
1 1
1 2
2 1
2 2
2 3
3 1
3 2
For every number in the first column I want it to have numbers 1 2 3 in the second column. As it is shown, Number 1 in the first column have 1 and 2 but doesn't have 3. I want to write a code that create a row which will be the third row in this matrix that writes 1 in the first column and 3 in the second column of this matrix. Similarly, I want the code to do the same thing and insert a last row as 3 in the first column have values of 1 and 2 but there is no 3. So, it will create a last row of [3 1].
I appreciate your help.

Best Answer

Why fill gaps? You can make new matrix obeying your conditions.
iwant = zeros(9,2) ;
iwant(:,2) = repmat([1 2 3],1,3);
k = repmat([1 2 3],3,1) ;
iwant(:,1) = k(:);