MATLAB: How to map a value of a vector into column number of a matrix

mappingvector

let A=[2;4;5] vector I want a matrix where all the values will be zero and the 2nd 4th and 5th element of column of 10×3 matrix will be 1.
B=[0 0 0
1 0 0
0 0 0
0 1 0
0 0 1
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0 ]

Best Answer

A = [2, 4, 5];
B = zeros(10, 3);
idx = sub2ind(size(B), A, 1:3);
B(idx) = 1;