MATLAB: Take specific elements from each cell of a cell array

cellcell arraycell arraysvector

Hello! Let A be a 1×10 cell array. Each of the 10 cells of A are nxm matrices.
Also, let an 1×10 vector x, that is, x=[ x1 x2 … x10 ].
I would like to take the x1 row from the first cell of A, the x2 row from the second cell of A, and so on for all the 10 cells of A.
I have tried cellfun, but I did not achive my goal.
Thanks in advance.

Best Answer

cellfun(@(a, X) a(X,:), A, x, 'uniform', 0)