Matlab 使用带有cellfun错误的setdiff
MyCell是一个5x10的字符串单元格(文件名)。我想根据字符串匹配在每5个单元格中删除一个元素 如果我键入:Matlab 使用带有cellfun错误的setdiff,matlab,cell-array,set-difference,Matlab,Cell Array,Set Difference,MyCell是一个5x10的字符串单元格(文件名)。我想根据字符串匹配在每5个单元格中删除一个元素 如果我键入: setdiff(MyCell{1,1}, {'Dontwant.mat'}) 它工作了,我得到了一个包含9个元素和其余元素的单元格 现在我想对每5个元素执行此操作,但如果我的脚本包括: MyCell=cellfun(@(x) setdiff({x},{'Dontwant.mat'}), MyCell , 'uniformoutput', 0); 我得到以下错误: 使用类的cel
setdiff(MyCell{1,1}, {'Dontwant.mat'})
它工作了,我得到了一个包含9个元素和其余元素的单元格
现在我想对每5个元素执行此操作,但如果我的脚本包括:
MyCell=cellfun(@(x) setdiff({x},{'Dontwant.mat'}), MyCell , 'uniformoutput', 0);
我得到以下错误:
使用类的cell/setdiff>CellSetDiff2012A(第292行)输入时出错
类单元格的单元格和输入B必须是字符串的单元格数组,除非
一个是字符串
单元格/setdiff中出错(第84行)
[varargout{1:nlhs}]=cellsetdiffR2012a(varargin{:})
任何帮助都将不胜感激。将传递给匿名函数的
x
已经是一个单元格数组,您不需要将其用大括号括起来{x}
,因此正确的版本是:
MyCell=cellfun(@(x) setdiff(x,{'Dontwant.mat'}), MyCell , 'uniformoutput', 0);
setdiff
在一个参数为string时也有效,因此您可以使用
MyCell=cellfun(@(x) setdiff(x,'Dontwant.mat'), MyCell , 'uniformoutput', 0);
删除
setdiff
中的{}
?