Index in position 2 exceeds array bounds (must not exceed 1).
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    sun rise
 el 29 de Mayo de 2022
  
    
    
    
    
    Respondida: sun rise
 el 31 de Mayo de 2022
            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 comentarios
Respuesta aceptada
  KSSV
      
      
 el 29 de Mayo de 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 comentarios
Más respuestas (2)
  Walter Roberson
      
      
 el 29 de Mayo de 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 comentarios
  Walter Roberson
      
      
 el 29 de Mayo de 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
Ver también
Categorías
				Más información sobre Matrix Indexing en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




