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!