error line:- Index in position 2 exceeds array bounds. Index must not exceed 4.
1 次查看(过去 30 天)
显示 更早的评论
%svm
train=DF;
xdata =train;
TrainingSet=double(xdata);
GroupTrain=[1;1;1;1;1;1;1;1;1;1;2;2;3;3]
TestSet=double(QF);
u=unique(GroupTrain);
numClasses=length(u);
result = zeros(length(TestSet(:,1)),1);
%build models
for k=1:numClasses
%Vectorized statement that binarizes Group
%where 1 is the current class and 0 is all other classes
G1vAll=(GroupTrain==u(k));
G1vAll=reshape(G1vAll(1,14))
mdl(k) = fitcsvm('G1vAll','result');
end
%classify test cases
for j=1:size(TestSet,1)
for k=1:numClasses
if(classificationsvm(mdl(k),TestSet(j,:)))
break;
end
end
result(j) = k;
end
out=result
%
回答(1 个)
Sandeep
2023-9-26
Hi Saiprathyush reddy,
It is great to know that you are working with the Support Vector Machine classifier.
The error occurs in the line mdl(k) = fitcsvm('G1vAll','result'); because you are passing the strings 'G1vAll' and 'result' as arguments to the 'fitcsvm' function. However, the 'fitcsvm' function expects the actual data as input, not the string representation of variable names.
To fix this error, you should pass the actual data to the 'fitcsvm' function.
Hope you find it helpful.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!