a Simple Matrix question

조회 수: 7 (최근 30일)
Li Chng
Li Chng 2019년 12월 27일
답변: David Goodmanson 2019년 12월 27일
if i have two
matrix_A = [ 200 201 130 150 202 203]
Matrix_B = [ 255 255 130 150 255 255]
how can i create Matrix_C such that
1) if the element inside Matrix_A and Matrix_B is identical it will display 255 in Matrix_C
2) and if they are not identical, it will display Matrix_A element
Ideal Matrix_C = [ 200 201 255 255 202 203]

답변 (2개)

David Goodmanson
David Goodmanson 2019년 12월 27일
Hello LC
Matrix_C = matrix_A;
Matrix_C(matrix_A == Matrix_B) = 255;

Bhaskar R
Bhaskar R 2019년 12월 27일
Matrix_C = matrix_A;
matrix_C(ismember(matrix_A, Matrix_B)) = 255;

태그

Community Treasure Hunt

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

Start Hunting!

Translated by