MATLAB: New column in matrix based on condition from other matrix

new column in matrix based on condition from other matrix

I have a matrix a = [ 1 11; 2 11; 3 12; 4 12; 5 13; 6 13] and b = [1;1;2;3;4;3;5;5;2;3] I want a new column in b based on the second column from a matrix i.e the output should be b = [1 11; 1 11; 2 11; 3 12; 4 12; 3 12; 5 13; 5 13; 2 11; 3 12]. Please can anyone help as soon as possible. it is very urgent!! Waiting for answers, Thanks in advance.

Best Answer

[found, arow] = ismember(b, a(:, 1));
assert(all(found), 'some elements of b are not in a');
b(:, 2) = a(arow, 2);