我運行下面這個程序,我不斷收到此錯誤「指數超過矩陣尺寸」線路「Tour1 =彈出(KK(1:10),:);」。我不知道我錯過了。任何人都可以請幫忙。 感謝指數誤差在for循環,MATLAB
for i = 1:100 %Population Initialization
pop(i,1) = 50 - rand*(50-1);
pop(i,2) = 1 - rand*(1-0.1);
pop(i,3) = 0.2 - rand*(0.2-0.01);
Kc(i) = pop(i,1);
T1(i) = pop(i,2);
T2(i) = pop(i,3);
fitness(i) = obj(Kc(i), T1(i), T2(i));
%% TOURNAMENT SELECTION
for j = 1:10 %Select first parent
kk = randperm(100);
Tour1 = pop(kk(1:10),:);
temp1 = mat2cell(Tour1(j,:),1,ones(1,numel(Tour1(j,:))));
ZET1(j) = obj(temp1{:});
end
[Val1 Ind1] = max(ZET1);
parent1 = Tour1(Ind1,:);
end
在Tour1中訪問它之前,您需要使用tofinish填充'pop'。使用debug:如果error''>> DBSTOP,看看'kk'和'pop'是 – Shai