MATLAB: Split matrix across the median

MATLABmatrix

How do I split a matrix across its median? Suppose I have a 5×10 matrix sorted in ascending order. I want to split this into two 5×5 matrices by finding the median of each row.
Then each sub-matrix will be further split k-times, for a huge matrix. The number of rows will remain constant.

Best Answer

If the rows are already sorted in ascending order, then the median is, by definition, right at the middle, so just index appropriately.
A1 = A(:,1:end/2);
A2 = A(:,end/2+1:end);