How can I plot particles (of a particle filter) with their weights in a color gradient way?

7 views (last 30 days)
I'm writing a particle filter and I would to plot a graphic like this, I don't know how to do that, I'm growing mad.
I plotted the mean of my particles and observed how it behaves comparing with the original state behavior. Basically I have k particle vectors (the axis name are inverted I think) each of Ns particles. I have also k associated and normalized weights vectors (the gradient bar on the right).
So in the end I would to plot every particle of every vector with its weight with a color gradient like in the picture below.
Any help would be appreciated and sorry for my english.
  1 Comment
bjan91
bjan91 on 28 Nov 2015
Hi Daniele,
"So in the end I would to plot every particle of every vector with its weight with a color gradient like in the picture below."
I am just working on this same problem (from what appears to be the same paper by Arulampalam) and I have a solution which is enough for me- hopefully it will get you started to what you need. I'll share the steps and the code below.
  1. Collect / Save weighted particles in a vector at each step
  2. Sort vector so that particles are in order from least to most important
  3. define a colormap and a linspace for the shading of the points by weight
  4. Plot within your figure using scatter.
% Manipulate weights and particles for plotting
for i = 1:ltvec-1
set1(1:Ns,1:2,i) =[update1(i,:,s)' P_w1(i,:,s)']; % [particles, weights]
set2(1:Ns,1:2,i) =[update2(i,:,s)' P_w2(i,:,s)'];
A = sortrows(set1(:,:,i),2); sorted1(:,i,s) = A(:,1);
B = sortrows(set2(:,:,i),2); sorted2(:,i,s) = B(:,1);
%sorted1 is the column of particles at the current timestep i, which
%are sorted and ordered according to weight ([least;.....;most]);
end
.....
...
.....
plot(ttvec,x1_set(:,j),'b-'); hold on; plot(ttvec,x1hat_interp(:,j),'r--');
colormap(gray)
c= linspace(1,10,size(sorted1,1));
for i=1:ltvec-1
scatter(tvec(i+1)*ones(Ns,1),sorted1(:,i,j),15,c);
end
Please refer to help documentation on linspace, scatter, and sort if you need. Hope this helps you; I was pleased with the result.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!