how to separate values of a matrix into 2 different matrix.

2 ビュー (過去 30 日間)
aditya sahu
aditya sahu 2017 年 4 月 29 日
回答済み: Image Analyst 2017 年 4 月 29 日
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.
  2 件のコメント
Stephen23
Stephen23 2017 年 4 月 29 日
@aditya sahu: what do you mean by "one matrix is less than 2": that the values should be less than two, or the number of elements should be less than two, or that it would contain the first two elements? I note that none of the elements has a value less than two.
aditya sahu
aditya sahu 2017 年 4 月 29 日
Dear stephen-cobeldick, thank you for correction, here my question relates to values only, i have updated the question.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2017 年 4 月 29 日
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.

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by