MATLAB: Choose row cell of matrix

cell arrays

I have
A=[1 2 0.1 0.2;...
1 5 0.2 0.2;...
2 3 0.4 0.4;...
2 4 0.9 0.8;...
2 5 0.3 0.4;...
3 4 1.1 2.2]
and
B={[1,2,5],[3,4,6]}
I want to get a C that rows of it, is B and column of it is all column of A
C=cell(1, size(B,2));
for i=1:length(B)
for j=1:length(B{i})
C{i}(j)=A(j,:)
end
end
I want this result
C={[1 2 0.1 0.2 ;...
1 5 0.2 0.2 ;...
2 5 0.3 0.4],...
[2 3 0.4 0.4 ;...
2 4 0.9 0.8 ;...
3 4 1.1 2.2]}

Best Answer

A general solution in one line:
C = cellfun(@(r)A(r,:),B,'uni',0)