How to plot the population/particle in Particle Swarm Optimization iteratively?

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)

hello, did u plot it if yes can you help me

3 Comments

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!
Hi! How did u save all the values (the X-positions) of your particles at each iteration?

Sign in to comment.

Asked:

on 6 Feb 2014

Commented:

on 5 Aug 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!