unequal vectors
Info
This question is closed. Reopen it to edit or answer.
Show older comments
I have a vector A for example of size 1500x1
matrix B size 817x2
A and B are numeric
All elements in column 1 in B are subset of A and all elements of B and A are uniquely identified.
I want to generate a matrix M(1500x2) such that the second column of M contains the elements of column 2 in B and zero whenever column1 in B isnot a member of A.
A= 10 11 12 13 14 15 16 17 ...
B column 1 is like 10 13 16
B column 2 is like 999 900 950
M col 1 is like 10 11 12 13 14 15 16 17
M col 2 is like 999 0 0 900 0 0 950 0
thx
Answers (2)
Andrew Newell
on 11 Jan 2012
tf = ismember(A,B);
C = 0*A;
C(tf) = B(:,2);
M = [A C]
Andrei Bobrov
on 11 Jan 2012
variant
M = A*[1 0]
M(ismember(A,B(:,1)),2) = B(:,2)
ADD [11:47(UTC+4) 11.01.2012]
can so?
A = [10 11 12 13 14 15 16 17]
B = [10 13 16; 999 900 950]
M = [1;0]*A
M(2,ismember(A,B(1,:))) = B(2,:)
EDIT [11:46(UTC+4) 18.12.2012]
[loga,idx] = ismember(A,B(:,1));
M = A*[1 0];
M(loga,2) = B(idx(loga),2);
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!