MATLAB Answers

a Simple Matrix question

3 views (last 30 days)
Li Chng
Li Chng on 27 Dec 2019
Answered: David Goodmanson on 27 Dec 2019
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]

  0 Comments

Sign in to comment.

Answers (2)

Bhaskar R
Bhaskar R on 27 Dec 2019
Matrix_C = matrix_A;
matrix_C(ismember(matrix_A, Matrix_B)) = 255;

  0 Comments

Sign in to comment.


David Goodmanson
David Goodmanson on 27 Dec 2019
Hello LC
Matrix_C = matrix_A;
Matrix_C(matrix_A == Matrix_B) = 255;

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags


Translated by