[問題] 不好意思 請問一下 已回收
不好意思,今天在寫這段時 一直沒辦法解決;
所以想請各位高手幫忙我看一下問題在哪邊 ><"
function new_popu=ga_operator (init_popu,popu_fit,n,xover_rate)
%selection
counter=0;
for z=1:n/2
parent1=0;
parent2=0;
new_popu=[];
x =rand();
y =rand();
check_point1 = 0
popu_fit_sum = cumsum(popu_fit)
xover_point = 3;
for i=1:n
surv_rate = popu_fit_sum(i) / sum(popu_fit)
check_point1 = x / sum(popu_fit)
while check_point1 < surv_rate
check_point1 = check_point1+1
end
if (check_point1 < surv_rate)
temp1 = init_popu(i,:)
parent1=temp1
break;
end
end
check_point1 = 0
for i=1:n
surv_rate = popu_fit_sum(i) / sum(popu_fit)
check_point1 = x / sum(popu_fit)
while check_point1 < surv_rate
check_point1 = check_point1+1
end
if (check_point1 < surv_rate)
temp2 = init_popu(i,:)
parent2=temp2
break;
end
end
check_point1 = 0
%crossover
if rand > xover_rate
new_popu(z*2-1,:)=[parent1(1:xover_point) parent2(xover_point+1:6)]
new_popu(z*2,:)=[parent2(1:xover_point) parent1(xover_point+1:6)]
else
new_popu(z*2,:)=[parent1]
new_popu(z*2-1,:)=[parent2]
end
end
然後執行時 跑出這段錯誤
??? Index exceeds matrix dimensions.
Error in ==> ga_operator at 65
new_popu(z*2,:)=[parent2(1:xover_point) parent1(xover_point+1:6)]
請問一下,我的語法或邏輯上哪邊出問題?
能不能給我個提示幫忙一下,感激不盡!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.126.143.29
推
05/22 15:52, , 1F
05/22 15:52, 1F
※ 編輯: k2 來自: 140.126.143.29 (05/22 16:01)
→
05/22 16:03, , 2F
05/22 16:03, 2F
推
05/22 17:10, , 3F
05/22 17:10, 3F
→
05/22 17:11, , 4F
05/22 17:11, 4F
→
05/22 17:11, , 5F
05/22 17:11, 5F
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章