简体   繁体   English

Matlab随机扩散数据的直方图

[英]Matlab Histogram of randomly spread data

I am a newbie to matlab and I already search a whole bunch of different sites but I didn't quite find a solution (at least an understandable one). 我是matlab的新手,我已经搜索了一大堆不同的网站,但我找不到解决方案(至少是一个可以理解的解决方案)。

I have a matrix 290x233 with double values ranging from 0.1 to 4.7. 我有一个矩阵290x233,其双值范围从0.1到4.7。 I want to generate a histogram out of all the data in this matrix in way that there are bars for a range of 0.5 -> I want to be able to see how many values there are within 0 to 0.5, from 0.5 to 1 and so on ... 我想从这个矩阵中的所有数据中生成一个直方图,其范围为0.5 - >我希望能够看到0到0.5之间有多少个值,从0.5到1等等上 ...

So far I managed to get kind of close plotting the bars. 到目前为止,我设法得到了密切关注酒吧的情节。 Using this code: 使用此代码:

bins=[0.25:0.5:4.75];
n2=histc(a_dif_1, bins);
bar(bins,n2,'hist');

I managed to get a result where there are a whole bunch of peaks within each bin (see image below). 我设法得到一个结果,其中每个bin中有一大堆峰值(见下图)。 This means it shows me the occurance of each single value within the bin range. 这意味着它向我显示了bin范围内每个单值的出现。

在此输入图像描述

then I found out about the "stacked" option and using 然后我发现了“堆叠”选项并使用了

bins=[0.25:0.5:4.75];
n2=histc(a_dif_1, bins);
bar(bins,n2,0.8,'stacked','b');

This way I at least got big bars just showing the TOTAL number of occurances within 1 bin (therefor 10 rectangleshaped bars shown below). 这样我至少得到了大棒,只显示1个箱内出现的TOTAL总数(因此下面显示了10个矩形条)。

在此输入图像描述

Right now I am wondering if this is the right way to draw bars just showing the total amount of values within a bin?? 现在我想知道这是否是绘制条形图的正确方法,只显示条形图中的总值? Apart of this I noticed that my bars I kind of getting set off the center of the bin (the bars to the right side are not axactly in the middle of two x-ticks) - did I mess something up with the bins?? 除此之外,我注意到我的酒吧我有点偏离垃圾箱的中心(右边的条不是在两个x-ticks的中间) - 我是不是把垃圾箱搞砸了?

As kind of a bonus I finally would like to draw a curve on top of the bars. 作为一种奖励,我最终想在酒吧顶部画一条曲线。 The curve should show follow the peaks I described before in a very generalized way so I can give a more detailed information about the distribution of the data apart of the bars. 曲线应该以非常概括的方式显示我之前描述的峰值,因此我可以提供有关条形数据分布的更详细信息。

Thanks for every kind of help or ideas! 感谢各种帮助或想法!

UPDATE UPDATE

THANK YOU VERY MUCH for the hints. 非常感谢您的提示。 I changed the histc to hist 我将histc更改为hist

bins=[0.25:0.5:4.75]; 
hist(a_dif_1(:), bins)

...and Matlab is giving me exactly what I wanted: ...... Matlab正在给我我想要的东西:

在此输入图像描述

a = 0.1;
b = 4.7;
r = a + (b-a).*rand(290,233);
bins=[0.25:0.5:4.75];
hist(r(:))
hist(r(:),bins)

is that ok for you? 这个可以吗?

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM