- Increase the number of bins, perhaps from 25 to 100 depending on what you want to do;
- Take log10(X) and use that instead.
histogram of a m-by-n matrix
5 次查看(过去 30 天)
显示 更早的评论
I have a m-by-n matrix of values between 10^-20 and 10^-8 I drew it by
hist(My_mat(:),15);
I obtain only one big bin of the hist, instead I would like to get several of bins between min and max values. Is it correct my code above ? Do you have any suggestions?
0 个评论
采纳的回答
Star Strider
2014-7-18
I would do one of two approaches, depending on what your data distribution is:
The first is probably the easiest. Experiment until you get the result you want.
6 个评论
Star Strider
2014-7-19
My pleasure!
This should do what you want:
log10Data = -randi(12,1,25)-8;
[bcnts,ctrs] = hist(log10Data,15); % Create histogram counts
bcnts = bcnts(bcnts>0); % Eliminate counts with bcnts = 0
ctrs = ctrs(bcnts>0); % Eliminate bins with bcnts = 0
ydat = 10.^ctrs.*bcnts; % Create new data for calculations
L10YData = log10(ydat); % Log10 of new data
mnD = mean(ydat); % Mean of edited data
L10mnD = log10(mnD); % Log10 of mean
figure(1)
bar(ctrs, bcnts); % Plot histogram
set(gca,'XTickLabel',''); % Clear default labels
ypos = min(ylim) - diff(ylim)*0.05; % Set y-position for ‘text’
hxt = [min(L10YData) L10mnD max(L10YData)]; % Set ‘hxt’ to be [min mean max]
for k1 = 1:length(hxt)
xtklbl{k1} = sprintf('10^{%2.0f}\n%s',hxt(k1)); % Create x-tick labels
end
text(hxt, ones(1,length(hxt))*ypos, xtklbl, 'HorizontalAlignment', 'center')
It may look a bit strange because of the way I had to recalculate your data with the zero-count bins eliminated. That is done in the ‘ydat’, and creates a data vector with the values of the data at the bin centers weighted by the counts. This skews the data, but is the only way I could calculate it and make the data work for the plot, because with the zero-bins included, the xtick labels did not work correctly. The outcome is that the data plotted is not the data you started with.
更多回答(1 个)
Image Analyst
2014-7-18
You should have 15 bins, though some of them might be virtually empty and too short to notice on the display. So do this:
counts = hist(My_mat(:), 15);
bar(counts, 'BarWidth', 1);
message = sprintf('You have %d bins', length(counts));
uiwait(helpdlg(message));
What does this say? So, if you do in fact actually have 15 bins then you might have to scale the data if you want to see all of the bins, like the others suggested. You can either scale the data values, or the counts - whatever it takes to see your data better.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Polar Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!