Index in position 2 exceeds array bounds (must not exceed 1).
8 次查看(过去 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!