Index in position 2 exceeds array bounds (must not exceed 1).
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
KSSV
am 29 Mai 2022
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 Kommentare
Weitere Antworten (2)
Walter Roberson
am 29 Mai 2022
A predicted label might exceed the number of actual labels.
Or heus might be empty, if some of the other variables are empty.
3 Kommentare
Walter Roberson
am 29 Mai 2022
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
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!