gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 06:14:53 26 4
gpt4 key购买 nike

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

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

enter image description here

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

enter image description here

如何保持比例不变?

我需要这个,因为下载的脚本不会生成直方图,所以我使用 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);

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

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

关于matlab - 如何创建直方图的直方图?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42653042/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com