This answer is the same as @Dan's, but using a simple for loop for performance improvement, if needed.
% If you know that the numel of elements returned by {2,2} will always be one:
nElem = numel(B);
ret(1,nElem)=0;
for k=1:nElem
ret(k) = A{1,B(k)}{2,2}
end
The following answer is wrong, it will only return the {2,2} index from the first element from B
subsref([A{1,B}],struct('type','{}','subs',{{2,2}}))
Which sounds more like what you are doing (and doesn't uses cellfun
and arrayfun
, that would be better if you are doing this operation on a loop, because they are slow)
See subsref
documentation here.
A longer path would be:
temp = [A{1,B}]
temp{2,2}