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

1 回表示 (過去 30 日間)
saiprathyush reddy
saiprathyush reddy 2022 年 3 月 12 日
回答済み: Sandeep 2023 年 9 月 26 日
%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
%
  2 件のコメント
saiprathyush reddy
saiprathyush reddy 2022 年 3 月 12 日
mdl(k) = fitcsvm('G1vAll','result');
saiprathyush reddy
saiprathyush reddy 2022 年 3 月 12 日
this is the point where the code gets stuck and the error occurs. hopefully there's all the information to help solve the confusion.

サインインしてコメントする。

回答 (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 Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by