2013-10-18 20 views
1

MyCell是一个5x10字符串单元格(文件名)。我想根据字符串匹配删除每个5个单元格中的一个元素。与cellfun一起使用setdiff给出错误

如果键入:

setdiff(MyCell{1,1}, {'Dontwant.mat'}) 

它的作品,我与其余元素的9元细胞。

现在我想为每个5元做到这一点,但如果我的剧本包括:

MyCell=cellfun(@(x) setdiff({x},{'Dontwant.mat'}), MyCell , 'uniformoutput', 0); 

我得到以下错误:

Error using cell/setdiff>cellsetdiffR2012a (line 292) Input A of class cell and input B of class cell must be cell arrays of strings, unless one is a string.

Error in cell/setdiff (line 84) [varargout{1:nlhs}] = cellsetdiffR2012a(varargin{:});

任何帮助将非常感激。

+0

删除'{}'在'setdiff'内? –

回答

3

将被传递到您的匿名功能x已经是一个单元阵列,你不需要包装在大括号{x}所以正确的版本是:

MyCell=cellfun(@(x) setdiff(x,{'Dontwant.mat'}), MyCell , 'uniformoutput', 0); 

setdiff也工作,如果一个参数是字符串,所以你可以简化它通过使用

MyCell=cellfun(@(x) setdiff(x,'Dontwant.mat'), MyCell , 'uniformoutput', 0); 
相关问题