在matlab中使用cellfun查找索引

时间:2015-11-17 16:46:28

标签: matlab

我正在尝试使用matlab找到一个使用cellfun的索引,我收到了这个错误:

??? Error using ==> cellfun
Input #3 expected to be a cell array, was double instead.

Error in ==> auc at 17
index = cellfun(@strcmp,y,labels(test));

代码:

indices = crossvalind('kfold',labels,10);
confusionMatrix = cell(1,1);
errorMat = zeros(1,10);
for i = 1:10
test = (indices==i);
train = ~test;
% Train the TreeBagger (Decision Forest).
model = TreeBagger(20,data,labels, 'Method', 'classification'); 
y = model.predict(data(test,:));
index = cellfun(@strcmp,y,labels(test));
errorMat(i) = sum(index)/length(y);
confusionMatrix{i} = confusionmat(labels(test),y);
end

1 个答案:

答案 0 :(得分:0)

我找到了答案。我应该将标签(测试)从数字转换为单元格

index = cellfun(@strcmp,y,labels(test));

变为:

index = cellfun(@strcmp,y,num2cell(labels(test)));