⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 histweight.m

📁 粒子滤波的源代码我自己觉得特别好可以了解粒子滤波有一个基础
💻 M
字号:
function [plotx,ploty]=histweight(x,w,N,edges)
%makes a histogram with N bins for the distribution of x, weighted with w.

[x,I]=sort(x);
w=w(I);

if(nargin<4)
binwidth=(x(end)-x(1))/N;
centers=linspace(x(1),x(end),N);
lim=linspace(x(1)-binwidth/2,x(end)+binwidth/2,N+1);
else
    binwidth=(edges(2)-edges(1))/N;
centers=linspace(edges(1),edges(2),N);
lim=linspace(edges(1)-binwidth/2,edges(2)+binwidth/2,N+1);
lim(end)=x(end);%to prevent out of bounds on the next few rows
end
y=zeros(1,N);

k=2;%points at the upper bin limit
for i=1:length(x)
    if(x(i)>lim(k))
        %ok, we must jump to the next bin
        k=k+1;
    else
        %we are still in the right bin
    end
        y(k-1)=y(k-1)+w(i); %add the weight to the bin               
end

%scale everything so that it is a real pdf
area=sum(y)*binwidth;
plotx=x;
ploty=y;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -