Copy values by indexation
Show older comments
Hi all, i am new and i have one question. I am trying to copy and paste values for one column of one array to other array with different size. I paste some pictures and code for my explanation:

The array A has two columns and i want copy the values of column two.

Then, i want to copy value of column 1 of A that match with column 1 of B and if match this values, copy values of column two of A in column two of B.
The result would be :

I had code but with loop. Is there some way with indexation?
Thank you very much and sorry for my poor explanation.
if true
% code
A=[1 12; 2 14; 3 18; 4 25; 5 32];
B=[1;1;1;2;2;3;3;3;4;4;5;5;5;5];
n = length(A); m = length(B);
for i = 1:m; for j = 1:n; if B(i,1) == A(j,1); B(i,2) = A(j,2); end end end
end
Accepted Answer
More Answers (0)
Categories
Find more on Matrix Indexing 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!