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

조회 수: 5 (최근 30일)
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.

채택된 답변

Image Analyst
Image Analyst 2012년 5월 26일
% 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;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by