function xmean=ObtainMeanTrajectory(xPF,w)

% ObtainMeanTrajectory   Calculates the mean trajectory given the particles and the weights
%
% xmean=ObtainMeanTrajectory(xPF,w)
%
% xPF: particles up to a given time step k
%      It is a NP*3*k matrix, each row a particle, the three columns for
%      (x,y,theta) and the third dimension for each time step
% w: weights
%      It is a NP vector, each row the weight for the particle
%      xPF(particle,:,:)
% xmean: mean value of the trajectory
%      It is a 3*k matriz. Each row for one of the elements of (x,y,theta),
%      each column for a given time step

% APRENDIZAJE AUTOMÁTICO (G. Pajares y J. M. de la Cruz, Eds.)
% Editorial: RA-MA
% Capítulo 8: Monte Carlo II
% Autores: Eva Besada-Portas, Sergey M. Plis


N=size(xPF,3);
wr=repmat(w,1,size(xPF,2));
for i=1:N
    xPF(:,:,i)= wr.*xPF(:,:,i);
end

xmean=squeeze(sum(xPF,1)); %Show the history information
