Error -Index exceeds matrix dimensions.

1 回表示 (過去 30 日間)
nkumar
nkumar 2013 年 1 月 10 日
I get error ,please tell how to rectify it,i have used 100x4 for training and rest for testing, even though i get error
clc
clear all
load fisheriris
groups = ismember(species,'setosa');
k=10;
groups =groups(1:100,:);
mt=meas(1:100,:);
mte=meas(101:end,:);
cvFolds = crossvalind('Kfold', groups, k);
cp = classperf(groups);
for i = 1:k
testIdx = (cvFolds == i);
trainIdx = ~testIdx;
svmModel = svmtrain(mt(trainIdx,:), groups(trainIdx), ...
'Autoscale',true, 'Showplot',false, 'Method','QP', ...
'BoxConstraint',2e-1, 'Kernel_Function','rbf', 'RBF_Sigma',1);
pred = svmclassify(svmModel, mte(testIdx,:), 'Showplot',false);
cp = classperf(cp, pred, testIdx);
end
  3 件のコメント
nkumar
nkumar 2013 年 1 月 10 日
Index exceeds matrix dimensions.
Error in ==> Untitl at 22 pred = svmclassify(svmModel, mte(testIdx,:), 'Showplot',false);
Jan
Jan 2013 年 1 月 12 日

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

回答 (1 件)

Walter Roberson
Walter Roberson 2013 年 1 月 10 日
Your cvFolds is constructed from groups, which is rows 1:100, but you use an index derived from that (testIdx) to index mte which is rows 101:end and so might be smaller.
  3 件のコメント
Jan
Jan 2013 年 1 月 12 日
How could we know, what you exactly want to achieve?
nkumar
nkumar 2013 年 1 月 12 日
i want to train the data with 100 data ant test the remaining

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by