I WANT TO KNOW WHY SO MUCH "." (dot) to define a statement, and does it mean something. Swarm.Particles(k).X ???
1 次查看(过去 30 天)
显示 更早的评论
for k = 1 : noP
Swarm.Particles(k).X = (ub - lb) .* rand(1,nVar) + lb;
Swarm.Particles(k).V = zeros(1,nVar);
Swarm.Particles(k).PBEST.X = zeros(1, nVar);
Swarm.Particles(k).PBEST.O = inf; % for minimization
end
*** Here they are storing the values in an array; noP = 300; nVar=10*****
回答(2 个)
Matt J
2020-7-16
编辑:Matt J
2020-7-16
It means (probably) that Swarm and some of its fields are struct arrays,
It could also be a more general object type,
It is generally not possible to tell what a variable is just from the way it is indexed. You must use whos() or class() to determine a variable's type.
2 个评论
Matt J
2020-7-17
You're welcome. Please accept-click the answer, though, if you consider your question resolved.
Image Analyst
2020-7-16
Swarm is a structure. It has one field called Particles. That field is another structure, but actually not a simple structure, but an array of structures, so it's a structure array with noP structures in the Particles array. Each of those structures in the Particles array has 3 fields: X, V, and PBEST. PBEST is another structure with 2 fields: X and O.
The loop iterates through assigning some value(s) to each structure in the Particles structure array that is a field of Swarm.
Does that help explain it?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Particle Swarm 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!