【问题标题】:How do I create a histogram of the samples with a delta of 0.01 in MATLab?如何在 MATLab 中创建增量为 0.01 的样本直方图?
【发布时间】:2020-11-10 16:26:55
【问题描述】:

我在区间上创建了一个包含 1,000,000 个均匀随机变量样本的数组 (0,1)。然后创建一个直方图,其中的值是生成的随机数。我不太明白使用 0.01 的 delta 来创建直方图。

rng('default')
array=rand(1000000,1);
[x,y]=hist(array,100)

【问题讨论】:

  • hist 已弃用。最好使用histogramhistogram(...,'BinWidth',BW)histogram(...,'BinLimits',[...]) 的语法可能是你想要的

标签: arrays matlab histogram gaussian delta


【解决方案1】:

您可以直接使用histogram 来生成情节

% Histogram binning and plot
edges = 0:0.01:1;
histogram( array, edges );

或者您可以使用histcounts 获取bin 数据,然后根据需要使用bar 轻松绘制。

% Histogram binning
edges = 0:0.01:1;
hc = histcounts( array, edges );
% Plot
centres = (edges(1:end-1)+edges(2:end))/2;
bar( centres, hc );

在这两种情况下,我在 edges 的定义中将 bin 大小指定为 0.01

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-05
    • 1970-01-01
    • 2014-07-17
    • 1970-01-01
    • 2013-02-06
    • 2017-07-27
    • 1970-01-01
    • 2011-06-21
    相关资源
    最近更新 更多