In this line (Line 163):
[x,fval]=ga(@(x) penalty2(x,available,bc,Dof,E,f,fixedcoord,na,nb,neft,nevt,nl,nn,numbitCoordX,numbitCoordY,numbitCoordZ,numbitEdof,numbitEp,sq,TOPGSM,xspan,yspan,zspan),(nn-nb-nl)*(numbitCoordX+numbitCoordY+numbitCoordZ)+(neft+nevt)*numbitEp+2*nevt*numbitEdof,options);
the ga function is taking this value:
(nn-nb-nl)*(numbitCoordX+numbitCoordY+numbitCoordZ)+(neft+nevt)*numbitEp+2*nevt*numbitEdof
to be ‘nvars’. It has to be an integer >0. I would use the ceil function to round it up to the next integer value, and include a check that it is >0.
For example, put this assignment and if block somewhere before your ga call:
Nvars = ceil((nn-nb-nl)*(numbitCoordX+numbitCoordY+numbitCoordZ)+(neft+nevt)*numbitEp+2*nevt*numbitEdof);
if Nvars <= 0
error('NVARS must be greater than zero.')
end
then when it meets the criteria, use ‘Nvars’ (or whatever you want to call it) in your ga call.
Best Answer