I have two geotiff images (saying "A" and "B") imported in Matlab as matrices with Geotiffread
. One has different values, while the second has only 0 and 255s.
What I'd like to do is replacing all the 255s with the values inside the other image (or matrix), according to their positions.
A and B differs in size, but they have the same projections.
I tried this:
A (A== 255)= B;
the output is the error:
??? In an assignment A(:) = B, the number of elements in A and B must be the same.
Else, I also tried with the logical approach:
if A== 255
A= B;
end
and nothing happens.
Is there a way to replace the values of A with values of B according to a specific value and the position in the referenced space?
A(A==255) = B(A==255)
. The error is telling you that when you try to assign values to the elements of an array, you cannot give it any more or fewer values than you are trying to assign. Also, re the if statement: I believe thatif A==255
means the same asif all(A==255)
, as in, if any elements ofA
are not255
, false is returned. You can check this at the command line. – darthbith