Clear Filters
Clear Filters

Index in position 2 exceeds array bounds

1 view (last 30 days)
Muhammad Izz Irfan
Muhammad Izz Irfan on 28 Dec 2020
Commented: Jan on 30 Dec 2020
How i want to solve this kind of problem ? I got an error Index in position2 exceeds array bounds
Error in RunMCSVMClassifier4 (line 20)
result = zeros(length(Xtest(:,1)),1);
function [err,M] = RunMCSVMClassifier4(Xtrain,Ytrain,Xtest,Ytest)
u=unique(Ytrain);
numClasses=length(u);
result = zeros(length(Xtest(:,1)),1);
models=[];
for k=1:numClasses
G1vAll=double(Ytrain==u(k));
models{k} = fitcsvm(Xtrain,G1vAll,'Standardize',true,....
'KernelFunction','RBF','KernelScale','auto');
end
%classify test cases
for j=1:size(Xtest,1)
for k=1:numClasses
if(predict(models{k},Xtest(j,:)))
break;
end
end
result(j) = k;
end
err=1-(sum(Ytest==result)/length(result));
if(nargout>1)
M=confusionmat(Ytest,result);
end
end
  1 Comment
Jan
Jan on 30 Dec 2020
Please post a complete copy of the error message, such that the readers do not have to guess, where the problem occurs.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!