MATLAB: Apply logical cell to a cell

cellcell arraycell arraysindexingMATLAB

I have:
– {A} which is a 100×1 cell with each cell element being a 44×1 matrix.
– {B} which is a 100×1 logical cell with each cell element being a 44×1 logical matrix.
I would like to know if there is a way to apply {B} to {A}, cell element by cell element, in order to filter the matrices contained in cell {A}.
Thanks

Best Answer

result = cellfun(@(a, b) a(b), A, B, 'UniformOutput', false)
will produce a 100x1 cell array of vectors (since filtering a matrix with a logical array always result in vectors).