在matlab中并排乘以直方图

use*_*846 9 matlab histogram

我想在matlab中生成如下的情节.

在此输入图像描述

或者可能是这样的 在此输入图像描述

Ste*_*eve 15

您可以使用bar(...)或hist(...)来获得所需的结果.请考虑以下代码,结果如下所示:

% Make some play data:
x = randn(100,3);
[y, b] = hist(x);

% You can plot on your own bar chart:
figure(82);
bar(b,y, 'grouped');
title('Grouped bar chart');

% Bust histogram will work here:
figure(44);
hist(x);
title('Histogram Automatically Grouping');

% Consider stack for the other type:
figure(83);
bar(b,y,'stacked');
title('Stacked bar chart');
Run Code Online (Sandbox Code Playgroud)

组栏结果 直方图结果 堆积条形结果

如果您的数据大小不同并且您想要做直方图,您可以自己选择容器来强制hist(...)结果大小相同,然后将结果绘制在矩阵中,如下所示:

data1 = randn(100,1);       % data of one size
data2 = randn(25, 1);       % data of another size!

myBins = linspace(-3,3,10); % pick my own bin locations

% Hists will be the same size because we set the bin locations:
y1 = hist(data1, myBins);   
y2 = hist(data2, myBins);

% plot the results:
figure(3);
bar(myBins, [y1;y2]');
title('Mixed size result');
Run Code Online (Sandbox Code Playgroud)

结果如下:

在此输入图像描述