使用
例如:
cellfun
,如何将一个函数应用于由mat2cell
函数创建的所有单元格?我的函数在另一个文件中定义,在此处它被引用为myFunc
。该函数需要两个参数,应该是一个单元格和一个整数。例如:
function H = myFunc(img,Q)
我的代码如下:% 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');
问题当然在于这一行代码:F = cellfun(@myFunc,C);
。我如何将单元格和所选择的整数(例如4)传递到myFunc
函数中,以便为每个单元格执行操作?
非常感谢。