Substituing values of a matrix
Show older comments
Hi everyone! I'm working on substituing values of a matrix with the values of another matrix. So for example, if I had
A = [1 2 3 ; 2 4 5 ; 4 1 3];
V = [1 10 ; 2 20 ; 3 30 ; 4 40 ; 5 50];
I'd like to substitue the values of A that are equal to the values of the first column of V, with the value of the second column of V. For the example, change in A 1 by 10, 2 by 20 and so on. Thank you!
Accepted Answer
More Answers (1)
Jan
on 26 Feb 2017
A = [1 2 3 ; 2 4 5 ; 4 1 3];
V = [1 10 ; 2 20 ; 3 30 ; 4 40 ; 5 50];
[match, index] = ismember(A(:), V(:, 1));
A(match) = V(index, 2)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!