MATLAB: I want to insert rows to matrix with condition

matrixmatrix manipulation

i have this matrix
D=[ 1 2 3 4 0 0
1 2 5 3 4 0
1 3 1 0 0 0
1 3 4 2 0 0
2 1 6 0 0 0
2 1 5 4 0 0
2 3 4 2 0 0
2 3 5 4 1 0
3 1 2 0 0 0
3 1 4 0 0 0 ]
i want to insert at each same raw ( same the 1&2 columns) for example
1 2 3 4 0 0
1 2 5 3 4 0
another raw (like 1&2 columns and 0 0 0 0)
1 2 0 0 0 0
for the matrix D become
D=[1 2 0 0 0 0
1 2 3 4 0 0
1 2 5 3 4 0
1 3 0 0 0 0
1 3 1 0 0 0
1 3 4 2 0 0
2 1 0 0 0 0
2 1 6 0 0 0
2 1 5 4 0 0
2 3 0 0 0 0
2 3 4 2 0 0
2 3 5 4 1 0
3 1 0 0 0 0
3 1 2 0 0 0
3 1 4 0 0 0 ]

Best Answer

your_mat = sortrows([a;b]);