MATLAB: Finding cell array elements

cell arrays

hi. I have a cell array containing many values like this:
x{2×1 cell;3×1 cell}
and each cell contains value like this:
x{1,1}={4;4}
x{2,1}={4;[1;4];[1;3]}
y=[0,0,1,-1,0,0; 1,0,-1,1,0,0] %2D array
I want to search elements of x one by one in corresponding row of y.
Thanks in advance

Best Answer

This would do it:
result = arrayfun(@(row) cellfun(@(columns) y(row, columns), x{row}, 'UniformOutput', false), ...
(1:size(x, 1)).', 'UniformOutput', false);