error line:- Index in position 2 exceeds array bounds. Index must not exceed 4.

8 次查看(过去 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
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.

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by