MATLAB: How to arrange rows in uitable

MATLABmatlab coderMATLAB Compilermatricesmatrixmatrix arraymatrix manipulationuitable

I have 2 matrices as below:
A=[1 2 3 0;1 2 4 5;0 9 7 0;1 3 4 6]; A=num2cell(A)
penalty=[-10; -20; -30; 0]
I need to do the code based on algorithm below:
1. arrange matrix A based on penalty. Highest penalty will produce highest row in the matrix. -30>-20>-10>0 Each row in matrix A referred to each row in matrix penalty. e.g: row 1 matrix A referred to -10. Therefore the result will like this:
newMatrix=
0 9 7 0
1 2 4 5
1 2 3 0
1 3 4 6
2. Then, divided the matrix into 2 new matrices, parentA and parentB with equal rows, with the rows above as parentA and rows below as parentB. If the number of newMatrix rows are odd, placed the greater rows in parentA. The result occured as below:
parentA=
0 9 7 0
1 2 4 5
parentB=
1 2 3 0
1 3 4 6
3. Combined back parentA and parentB in a matrix again by rows of parentA as odd rows and parentB as even rows. The result occured as below:
newMatrix2=
0 9 7 0
1 2 3 0
1 2 4 5
1 3 4 6
4. Finally, I need to arrange back the newMatrix2 into original form again as matrix A.
originalMatrixA=
1 2 3 0
1 2 4 5
0 9 7 0
1 3 4 6
This algorithm I need as trick to arrange my code, but I'm not very capable to do it. This code I need to apply to more rows in A such as 100 or 899 rows. I need any help to solve this problem.

Best Answer

To start :
Answer 1:
[sorted,d]=sort(penalty);
newMatrix= A(d,:);
Answer 2:
parentA= newMatrix(1:2,:);
parentB= newMatrix(3:4,:);