MATLAB: Cellfun for function with multiple inputs

cellfun cell arrays

I want to apply a function to every cell within a cell array, so using cellfun seems the logical way to go. But the function requires two inputs, one would be the cell array,A, and the other is B, a 41×1 matrix. So the function would 'apply' B to each cell within A and output the resultant arrays into another cell array
C = cellfun(@func, B, A, 'UniformOutput', false);
Is what I've been doing but it returns the error:
Input #3 expected to be a cell array, was double instead.
Can someone explain how cellfun works for functions with multiple inputs?

Best Answer

Isn't the error obvious about what you should be doing?
Input #3 expected to be a cell array, was double instead.
Your third input should also be a cell array, but it is double. So convert your double array to cell array by mat2cell, and then apply the cellfun.