How to plot the population/particle in Particle Swarm Optimization iteratively?
Ältere Kommentare anzeigen
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?
Antworten (1)
khadija portu
am 19 Mai 2019
1 Stimme
hello, did u plot it if yes can you help me
3 Kommentare
Mouktar Bello
am 11 Mai 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
am 17 Aug. 2020
Thank you ! That's helpful
Michela Trapani
am 5 Aug. 2021
Hi! How did u save all the values (the X-positions) of your particles at each iteration?
Kategorien
Mehr zu Particle Swarm finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!