MATLAB: How to separate values of a matrix into 2 different matrix.

digital image processingimageimage acquisitionimage processingimage segmentation

I have a matrix of 2*2=4 elements.Let it be x= [2 3 ; 4 5] i want separate the matrix into 2 matrixes. one matrix contains values should be less or equals to 2 and other matrix should contain values more than 2, and again i want to merge them back. Can anybody suggest how to do? Thank you.

Best Answer

Try this:
x= [2 3 ; 4 5]
mask = x <= 2;
x2 = x .* mask
x3 = x .* ~mask % Multiply by the inverse of the mask.
x4 = x2 + x3 % Combine together.