if i have an initial array A of twenty numbers in the order 1 to 20,
A = [1,2,3,4,5,...,20]
and have another random array B:
B = [1, 15, 3, 20, 7]
and want to output a column vector C of the form
C = [1 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 1]
Note that C has a 1 at the indices at which B has a value.
I have tried the following:
n=20;
C = zeros(n, 1);
for i=1:length(B)
C(B(i))=1;
end
Ahas got to do with anything?