I want to find and replace numbers in a large matrix A. Vectors B and C have the same dimensions and contain values. Even though A may contain non-unique values, it has all the numbers of B. I want to search A for all values in B and replace them with the corresponding values in C.
For example, let A be a 2.5·106×4 matrix. B and C are 1.5·106×1 and have unique values. I've tried using the following for loop:
for q = 1:size(B, 1)
A(A == B(q, 1)) = C(q, 1);
end
But it is very slow. Is there a faster way to do this?