我想将一个函数应用于单元格数组的每个元素-所以我cellfun提供了cellfun 。但是,该函数需要两个额外的参数(字符串和向量),我想对单元格数组的所有元素保持不变;即我想做类似的事情:
cellfun(@myfun, cellarray, const1, const2) 含义:
for i = 1:numel(cellarray), myfun(cellarray{i}, const1, const2); end 有没有一种方法可以创建不包含const1和const2 numel(cellarray)副本的中间单元格数组?
回答:
您可以使用
匿名函数来执行此操作,该
函数使用另外两个参数调用myfun :
cellfun(@(x) myfun(x,const1,const2), cellarray)
更多&回答...