MATLAB: Array indexing with repeated index, index size larger than the array

indexing

Hi
I want to do c = 1; for i = I B(c) = A(i); c = c + 1; end
where I is a vector.
For instance A = [a b c d]; I = [1 1 3 1 1 1 2 2 1]; then B = [a a c a a a b b a];
is there a fast way to do this without for loop?
Thanks

Best Answer

One way:
A = {'a' 'b' 'c' 'd'};
I = [1 1 3 1 1 1 2 2 1];
B = A(I);