Revision: 39810
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at January 21, 2011 07:19 by gobbledygook88
Initial Code
%==========================================================
% Plots a histogram
% + Frequency labels
% + Bin edges
%==========================================================
% Number of bins
binNumbers = 10;
% Load in data (single column data file)
data = load('data.out');
% Close any graphs currently open
close all;
% Plot histogram
hist(data,binNumbers);
% Run hist function again to grab bins
[n,xout] = hist(data,binNumbers);
% Set length of bins
binLength = length(xout);
% Make graph fullscreen
set(gcf, 'Position', get(0,'Screensize'));
% Graph labels
xlabel('Bins');
ylabel('Count');
title('Histogram');
% Y-Offset value. Change accordingly
offsetY = 33;
% Put counts over the bars.
for bin = 1 : binLength
caption = sprintf('%d', n(bin));
text(xout(bin), n(bin)+offsetY, caption, 'VerticalAlignment','bottom', 'HorizontalAlignment', 'center');
end
% Bin edge variables
max = max(data);
min = min(data);
width = ( max - min ) / binNumbers;
ticks = min:width:max;
% Set new intervals
set(gca,'XTick', ticks);
Initial URL
Initial Description
Plots a histogram from an external file with the frequency of each bin shown above each bar. The XTick is also the intervals of the histogram.
Initial Title
Histogram Styles
Initial Tags
Initial Language
MatLab