在MATLAB中并排相乘直方图 [英] side by side multiply histogram in matlab

查看:113
本文介绍了在MATLAB中并排相乘直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在matlab中生成如下图所示.

I would like to produce a plot like the following in matlab.

或者可能是这样的

推荐答案

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

You can use bar(...) or hist(...) to get the results you want. Consider the following code with results shown below:

% 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');

如果数据大小不同,并且想要进行直方图处理,则可以自己选择垃圾箱以将hist(...)结果强制为相同大小,然后将结果堆叠在矩阵中,如下所示:

If your data is different sizes and you want to do histograms you could choose bins yourself to force hist(...) results to be the same size then plot the results stacked up in a matrix, as in:

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');

具有以下结果:

这篇关于在MATLAB中并排相乘直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆