Copy values by indexation
显示 更早的评论
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
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!