Effacer les filtres
Effacer les filtres

How can I substitute values in a matrix if they equal a certain value?

1 vue (au cours des 30 derniers jours)
Claire
Claire le 16 Avr 2014
Commenté : Claire le 16 Avr 2014
I have two matrices X1 and X2 (both have dimensions 512x512) I would like to write code to create a new matrix that has the element values from X1 in, unless the element equals 255- in which case I would like to use the element from the same coordinate from X2 instead.
I hope this makes sense! Thanks for your help :)

Réponse acceptée

Mischa Kim
Mischa Kim le 16 Avr 2014
Modifié(e) : Mischa Kim le 16 Avr 2014
Claire, you could use something like
X3 = X1;
X3(X1==255) = X2(X1==255);

Plus de réponses (1)

lvn
lvn le 16 Avr 2014
I hope this is what you mean:
newmatrix=X1;
newmatrix(X1==255)=X2(X1==255);

Catégories

En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by