A is 50*85 matrix and B is 30*85 matrix. All I need is to delete ith row in matrix A and insert it at the end of B matrix. New matrix will be A =49*85 and B= 31*85. A and B are two different data sets which doesn't depend on anything. I select the row'i' using a third matrix which is 30*50. If row i in the third matrix is the max of the minimums ([maxValue, rowIdx] = max(C(1,end),,1)) then I remove ith row from A and insert it into B. I use the rowIDx to determine the ith row (row that has maxi of the minimum) which will help me to remove from A using A(rowIdx,:)= I hope this information will help to solve my issue.