MATLAB: How to index using cell arrays

cell arraysindexing

A = randi(100,1,8); % Some array that I want to index into.
B = {[1;2;3];[4;5];[6];[7;8]}; % Cell array with indices.
%I want to index B into A to get:
C = {[A(1);A(2);A(3)];…;[A(7);A(8)]}

Best Answer

cellfun(@(b) A(b), B, 'UniformOutput', false)