如何创建直方图的直方图?

How to create a histogram plot of a histogram?

我使用两个脚本创建直方图,一个是 matlab 自带的 hist 函数,另一个是我下载的脚本。我下载的脚本采用绝对最小值和最大值并生成两者之间的直方图。但问题是,与 MATLAB 不同,此直方图不会显示。我看到了一个矢量。

现在我正在使用 plot 比较两者的视觉效果,但由于某种原因,比例发生了变化。例如,使用 MATLAB 的 hist 的直方图如下所示:

如果我在 plot 中显示此直方图,则 x 轴比例会发生变化:

如何保持比例不变?

我需要这个,因为下载的脚本不会生成直方图,所以我使用 plot 来显示它。同样,情节在 0 到 100 之间,我觉得这可能不是一个准确的比较

您似乎没有使用所有可用的信息。请参阅下面的代码,了解如何完成您想要的操作的示例:

%% Generate some data:
rng(42653042);
data = randn(300); data = (data-min(data(:)))*90+100;
data(1:4:end) = data(1:4:end)/2;
%% Plot using hist:
figure(); hist(data(:),100);
%% Return bin info using hist:
[N,X] = hist(data(:),100);
%% Plot the other function's output w/o X:
figure(); plot(N);
%% Plot the other function's output w/ X:
figure(); plot(X,N);
figure(); bar(X,N);

函数 hist 在较新版本的 MATLAB 中应替换为:

  • histogram,当用于绘图时(即 hist 没有输出的情况)。
  • histcounts,当用于计数时(即 hist 输出的情况)。

使用 "n = hist(Y,x) where x is a vector, returns the distribution of Y among length(x) bins with centers specified by x" 指定 bin 中心。