2016-07-13 24 views
0

下面的代碼段:如何索引ClassificationSVM類的對象?

for i = 1:length(tempclasses) 
    for j=i+1:length(tempclasses) 
     ind1=find(strcmp([classes.class1],tempclasses(i))); 
     ind2=find(strcmp([classes.class2],tempclasses(j))); 
     ind=intersect(ind1,ind2); 
     tmp=predict(SVMModel(ind).svm, histr); 
     ind=find(strcmp({t.ind}, tmp)); 
     t(ind).fit=t(ind).fit+1; 
    end 
end 

給出了錯誤:

Error using classreg.learning.internal.DisallowVectorOps/subsref (line 16) You cannot index into an object of class ClassificationSVM using() indexing.

是否有任何想法如何解決呢?

+0

你需要創建一個最小的工作示例(HTTP:/ /stackoverflow.com/help/mcve),否則不容易提供幫助 – ead

回答

0

i應停止在length(tempclasses)-1代替length(tempclasses)

否則j將在i+1至極開始是大於length(tempclasses)這將不分配一個值j