array indexing with repeated index, index size larger than the array
1 view (last 30 days)
Show older comments
Sung-En Chiu
on 29 Aug 2018
Commented: Sung-En Chiu
on 30 Aug 2018
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
0 Comments
Accepted Answer
Andrei Bobrov
on 29 Aug 2018
One way:
A = {'a' 'b' 'c' 'd'};
I = [1 1 3 1 1 1 2 2 1];
B = A(I);
5 Comments
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!