Index exceeds matrix dimensions
Show older comments
function [InitFunction, CostFunction, FeasibleFunction] = MLP_Heart
InitFunction = @MLP_HeartInit;
CostFunction = @MLP_HeartCost;
FeasibleFunction = @MLP_HeartFeasible;
return;
function [MaxParValue, MinParValue, Population, OPTIONS] = MLP_HeartInit(OPTIONS)
global MinParValue MaxParValue
Granularity = 0.1;
MinParValue = -10;
MaxParValue = 10;
%MaxParValue = floor(1 + 2 * 2.048 / Granularity);
% Initialize population
for popindex = 1 : OPTIONS.popsize
chrom = (MinParValue + (MaxParValue - MinParValue) * rand(1,OPTIONS.numVar));
Population(popindex).chrom = chrom;
end
OPTIONS.OrderDependent = true;
return;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [Population] = MLP_HeartCost(OPTIONS, Population)
load Heart.txt
x=Heart;
%I2=x(1:80,1:4);
I2(:,1)=x(1:80,2);
I2(:,2)=x(1:80,3);
I2(:,3)=x(1:80,4);
I2(:,4)=x(1:80,5);
I2(:,5)=x(1:80,6);
I2(:,6)=x(1:80,7);
I2(:,7)=x(1:80,8);
I2(:,8)=x(1:80,9);
I2(:,9)=x(1:80,10);
I2(:,10)=x(1:80,11);
I2(:,11)=x(1:80,12);
I2(:,12)=x(1:80,13);
I2(:,13)=x(1:80,14);
I2(:,14)=x(1:80,15);
I2(:,15)=x(1:80,16);
I2(:,16)=x(1:80,17);
I2(:,17)=x(1:80,18);
I2(:,18)=x(1:80,19);
I2(:,19)=x(1:80,20);
I2(:,20)=x(1:80,21);
I2(:,21)=x(1:80,22);
I2(:,22)=x(1:80,23);
T=x(1:80,1);
Hno=45;
dim = 24*45+1;
global MinParValue MaxParValue
popsize = OPTIONS.popsize;
for popindex = 1 : popsize
Population(popindex).cost = 0;
for ww=1:23*Hno
W(ww)=Population(popindex).chrom(1,ww); /* Index exceeds matrix dimension*/
end
for bb=23*Hno+1:dim
B(bb-(23*Hno))=Population(popindex).chrom(1,bb);
end
fitness=0;
for pp=1:80
actualvalue=my_simulate(22,Hno,1,W,B,I2(pp,:));
fitness=fitness+(T(pp)-actualvalue)^2;
end
fitness=fitness/80;
Population(popindex).cost=fitness;
end
return
function [Population] = MLP_HeartFeasible(OPTIONS, Population)
global MinParValue MaxParValue
for i = 1 : OPTIONS.popsize
for k = 1 : OPTIONS.numVar
Population(i).chrom(k) = max(Population(i).chrom(k), MinParValue);
Population(i).chrom(k) = min(Population(i).chrom(k), MaxParValue);
end
end
return;
1 Comment
Image Analyst
on 9 Dec 2020
I took the code and put it into a script and attached it. It runs fine. But it never gets to the line of code where you put the comment so I can't reproduce your error. How do we get it to run that function?
Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!