【问题标题】:Is there anyway to find the density of histogram values in MATLAB?无论如何在MATLAB中找到直方图值的密度?
【发布时间】:2015-07-20 22:06:15
【问题描述】:

我有 7 个向量,范围在 0 到 0.99 之间。每个向量中的条目数是不同的,因此比较它们的直方图是“不公平的”,因为假设变量是间隔的,bin 计数和条目数之间应该存在直接相关性。我有兴趣绘制值密度的平滑曲线。因此,对于一个向量 a 的 n 值从 0 到 0.99,我想要一个 0 到 0.99 的 x 轴,y 轴是与这些值相关的概率。

有什么想法或见解吗?

【问题讨论】:

    标签: matlab histogram distribution probability-density


    【解决方案1】:

    不确定你想要什么样的平滑,但知道如何开始:

    %some example vectors of different length
    p=[10,100,1000,10000];
    D=arrayfun(@(x)(rand(x,1)),p,'uni',false);
    %defining the range
    support=[0:.1:1];
    %make sure we don't miss a value
    esupport=support;
    esupport(end+1)=inf;
    %define a function which uses histc to calculate the emperical probability for each bin
    epdf_bin=@(x)histc(x,esupport)/numel(x);
    %evaluate emperical probability
    E=cellfun(epdf_bin,D,'uni',false);
    
    M=cat(2,E{:});
    %plot
    bar(M);
    %print legend
    legend(arrayfun(@num2str,p,'uni',false));
    %fix x axis labels
    set(gca,'XTick',.5:numel(support))
    set(gca,'XTickLabel',support)
    

    【讨论】:

    • 抱歉打扰了,但是有没有办法让这个直方图看起来像一条曲线?
    • 据我了解,绘制曲线是错误的。您没有 pdf,也无法从数据中获取。
    【解决方案2】:
    [h,b] = hist( my_data, Nbins );
    plot( b, h / sum(h) );
    

    【讨论】:

      猜你喜欢
      • 2017-03-21
      • 2017-11-26
      • 1970-01-01
      • 2018-01-13
      • 1970-01-01
      • 2014-11-29
      • 2015-05-01
      • 1970-01-01
      • 2013-01-25
      相关资源
      最近更新 更多