Number of variables (NVARS) must be a positive integer.
30 次查看(过去 30 天)
显示 更早的评论
I want to run a project using genetic algorithm but I get this error every time.
I know what is it but I don't know how to fix it.
this is my project that I attached and the main function is GAmodule.
you can start with these numbers :
235
2
1
4
0
0
0
10
0
0
5
0
10
0
0
1000
g
700
Thank you
1 个评论
采纳的回答
Star Strider
2014-8-23
编辑:Star Strider
2014-8-23
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Genetic Algorithm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!