How the replace values in one matrix by comparision with another?

1 vue (au cours des 30 derniers jours)
Robert
Robert le 26 Mai 2012
Hi Matlab users,
My problem is this: I have 2 matrix of the same size let's say A=(238;132;70) and B=(238;132;70). They have different contents but matrix A has the number -99 a lot of times in it (which represents land) and matrix B has also the number -99 in it, but fewer values. How can I make so that matrix B will keep it's own values, except for the points where matrix A has -99 value, case in which it will write -99?
Best regards,
Robert.

Réponse acceptée

Image Analyst
Image Analyst le 26 Mai 2012
% Get a logical map of where -99 occurs in A
locations99inA = (A == -99);
% Assign ONLY THOSE locations in B to be 99
% leaving all other elements of B unchanged.
B(locations99inA) = -99;
  1 commentaire
Robert
Robert le 26 Mai 2012
You have my thanks, sir. It's working like a charm.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by