How do I apply a function with multiple parameters using `cellfun` (MATLAB)?
cell-array, divide, image-processing, matlab, matrix
Solution
Well, simply define a new anonymous function as `@(x) myFunc(x,4)` and use it this way:
F = cellfun(@(x) myFunc(x,4), C)
Problem
Using `cellfun`, how do I apply a function to all the cells created by the `mat2cell` function? My function is defined in another file, here it is referred to by `myFunc`. This function takes two arguments, which should be a cell and an integer. e.g. `function H = myFunc(img,Q)` My code is as follows: ``` % Split into grid and process each cell width = size(img,2) % get image width height = size(img,1) % get image height depth = size(img,3) % get depth C = mat2cell(img,[height/2 height/2],[width/2 width/2],[depth/2 depth/2]); % divides image into sections F = cellfun(@myFunc,C); save(fout,'F'); ``` The issue is of course with the line `F = cellfun(@myFunc,C);`. How do I pass the cells and a chosen integer e.g. 4 into `myFunc` for each cell? Many thanks.