Index in position 2 exceeds array bounds (must not exceed 1).
조회 수: 9 (최근 30일)
이전 댓글 표시
load featurs_T
load featurs_S
load Group_Train
load Group_Test
load actual_label
load predict_label
load predict_label
%WEIGHTEDVOTING is a proposed ensemble method
k = max(actual_label); % determining number of classes [1-K]
heus = [];
%HOG_SVM = multisvm(Feat1,Group_Train1,Feat2,Group_Test1);
rec = recall(predict_label, actual_label); prec = precision(predict_label, actual_label);
heus = [heus; 2*f1(prec,rec)-FPR(predict_label, actual_label)];
%LBP_SVM = multisvm(Feat1,Group_Train1,Feat2,Group_Test1);
rec = recall(predict_label2, actual_label); prec = precision(predict_label2, actual_label);
heus = [heus; 2*f1(prec,rec)-FPR(predict_label2, actual_label)];
res = zeros(length(actual_label),length(k));
for i=1:length(actual_label)
res(i,predict_label(i)) = res(i,predict_label(i)) + heus(1);
res(i,predict_label2(i)) = res(i,predict_label2(i)) + heus(2);
end
[~, preds] = max(res,[],2);
Index in position 2 exceeds array bounds (must not exceed 1).
Error in weightedVoting (line 27)
res(i,predict_label(i)) = res(i,predict_label(i)) + heus(1);
댓글 수: 0
채택된 답변
KSSV
2022년 5월 29일
This is a simple error. You are trying to extract more number of elements then present in the array.
% Example
A = rand(1,5) ; % size of A is 1x5
A(1) % no error
A(4) % no error
A(end) % no error, this will give you 5th element
A(6) % error, there is no 6th element
Like wise check the dimensions of each array and use looping.
댓글 수: 0
추가 답변 (2개)
Walter Roberson
2022년 5월 29일
A predicted label might exceed the number of actual labels.
Or heus might be empty, if some of the other variables are empty.
댓글 수: 3
Walter Roberson
2022년 5월 29일
k is the maximum label, which is a scalar. length(k) is 1. You use length(k) as the upper bound for the size of res so res is 120 by 1 instead of 120 by the number of labels
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!