How to plot the population/particle in Particle Swarm Optimization iteratively?
Show older comments
I did some programming about PSO. I want to show the movement of my particles/swarms every iteration. It will show like animation because every particle will move based on the result of every iteration. Anyone can help me with the coding or has any idea about this?
Answers (1)
khadija portu
on 19 May 2019
1 vote
hello, did u plot it if yes can you help me
3 Comments
Mouktar Bello
on 11 May 2020
I see your questions are dated. So I'll answer for other people.
You need to store all the values (the X-positions) of your particles at each iteration, and then you just make a loop to display each iteration.
For example if you have this form Swarm(n).Particles(i).X to designate the X position of the i-th particle at the n-th iteration, you can use this code:
for n= 1: max_Iteration
clf;
for j=1:noP
plot(Swarm(n).Particles(j).X(1),Swarm(n).Particles(j).X(2),'k.', 'MarkerSize', 30)
hold on
grid on
end
pause(1); %Pause a little bit before plotting the next iteration
end
Where noP: is number of particles
And here you go!
Bhaskar Tripathi
on 17 Aug 2020
Thank you ! That's helpful
Michela Trapani
on 5 Aug 2021
Hi! How did u save all the values (the X-positions) of your particles at each iteration?
Categories
Find more on Particle Swarm 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!