问题描述
我想对矩阵的每一列进行直方图绘制,但是我希望这些分格是对数的并且也要归一化.在创建直方图之后,我想在其上拟合而不显示条形图.这是我尝试过的:
I would like to make a histogram of every column of a matrix, but I want the bins to be logarithmic and also normalized. And after I create the histogram I want to make a fit on it without showing the bars. This is what I have tried:
y=histogram(x,'Normalized','probability');
这段代码为我提供了标准化的直方图,但是,我不知道如何使垃圾箱记录下来. 预先谢谢你!
This code gives me the histogram normalized, but, I don't know how to make the bins log. Thank you in advance !!
推荐答案
创建对数直方图的方法有两种:
There are two different ways of creating a logarithmic histogram:
-
计算数据对数的直方图.这可能是最好的方法,因为您让软件决定要创建的仓数,等等.x轴现在不匹配您的数据,而是匹配您的数据日志.对于拟合功能,这可能是有益的,但对于显示,可能会造成混淆.在这里,我更改了刻度线标签以显示实际值,同时使刻度线本身保持其原始值:
Compute the histogram of the logarithm of the data. This is probably the nicest approach, as you let the software decide on how many bins to create, etc. The x-axis now doesn't match your data, it matches the log of your data. For fitting a function, this is likely beneficial, but for display it could be confusing. Here I change the tick mark labels to show the actual value, keeping the tick marks themselves at their original values:
y = histogram(log(x),'Normalization','probability');
h = gca;
h.XTickLabels = exp(h.XTick);
以对数标度确定您自己的垃圾箱边缘.在这里,您需要根据样本数量和样本分布来确定需要多少个容器.
Determine your own bin edges, on a logarithmic scale. Here you need to determine how many bins you need, depending on the number of samples and the distribution of samples.
b = 2.^(1:0.25:3);
y = histogram(x,b,'Normalization','probability');
set(gca,'XTick',b) % This just puts the tick marks in between bars so you can see what we did.
使用方法1,MATLAB可以根据输入数据自动确定bin的数量和bin边缘.因此,它不适合创建多个匹配的直方图.在这种情况下,请使用方法2.可以通过这种方式更简单地获得in边缘:
Method 1 lets MATLAB determine number of bins and bin edges automatically depending on the input data. Hence it is not suitable for creating multiple matching histograms. For that case, use method 2. The in edges can be obtained more simply this way:
N = 10; % number of bins
start = min(x); % first bin edge
stop = max(x); % last bin edge
b = 2.^linspace(log2(start),log2(stop),N+1);
这篇关于直方图,对数分类并归一化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!