pet*_*llw 8 matlab image-processing matrix divide cell-array
使用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');
Run Code Online (Sandbox Code Playgroud)
问题当然在于这条线F = cellfun(@myFunc,C);.如何myFunc为每个单元格传递单元格和选定的整数,例如4 ?
非常感谢.
kne*_*epp 12
好吧,只需将新的匿名函数定义为@(x) myFunc(x,4)并以这种方式使用它:
F = cellfun(@(x) myFunc(x,4), C)
Run Code Online (Sandbox Code Playgroud)