我有来自mat文件的8个功能 每个功能分为4部分(X_train,Y_train,X_test,Y_test) 10次随机获得此参数 现在我应该根据KNN对这个功能进行分类 我的代码在这里
kk=7;
bb=1;
mdl1= ClassificationKNN.fit([X1_train{bb};X2_train{bb};X3_train{bb};X4_train{bb};X5_train{bb};X6_train{bb};X7_train{bb};X8_train{bb};X9_train{bb};X10_train{bb};X11_train{bb};X12_train{bb}],[Y1_train{bb};Y2_train{bb};Y3_train{bb};Y4_train{bb};Y5_train{bb};Y6_train{bb};Y7_train{bb};Y8_train{bb};Y9_train{bb};Y10_train{bb};Y11_train{bb};Y12_train{bb}],'NumNeighbors',kk);
.
.
.
bb=10;
mdl10= ClassificationKNN.fit([X1_train{bb};X2_train{bb};X3_train{bb};X4_train{bb};X5_train{bb};X6_train{bb};X7_train{bb};X8_train{bb};X9_train{bb};X10_train{bb};X11_train{bb};X12_train{bb}],[Y1_train{bb};Y2_train{bb};Y3_train{bb};Y4_train{bb};Y5_train{bb};Y6_train{bb};Y7_train{bb};Y8_train{bb};Y9_train{bb};Y10_train{bb};Y11_train{bb};Y12_train{bb}],'NumNeighbors',kk);
如您所见,此功能重复10次以评估10 mdl 在下面我写这段代码来简化项目
for j=1:10
for h=1:12
mdl{j}{h}=ClassificationKNN.fit([X_train{j}{h}],[Y_train{j}{h}]);
end
end
此代码工作正常没有(mdl {j} {h})但是如果使用这句话我有这个错误消息((单元格内容分配给非单元格数组对象)) anybode知道我该怎么做才能解决这个问题 感谢
答案 0 :(得分:0)
首先你应该定义mdl变量大小
mdll= cell(10, 8);
然后形成这个for循环
for j=1:10
mdll{j}= ClassificationKNN.fit([X_train{j}{1};X_train{j}{2};X_train{j}{3};X_train{j}{4};X_train{j}{5};X_train{j}{6};X_train{j}{7};X_train{j}{8};X_train{j}{9};X_train{j}{10};X_train{j}{11};X_train{j}{12}],[Y_train{j}{1};Y_train{j}{2};Y_train{j}{3};Y_train{j}{4};Y_train{j}{5};Y_train{j}{6};Y_train{j}{7};Y_train{j}{8};Y_train{j}{9};Y_train{j}{10};Y_train{j}{11};Y_train{j}{12}],'NumNeighbors',kk);
end
我检查了它并正常工作