-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpHst.m
54 lines (46 loc) · 1.07 KB
/
pHst.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
function [tL,tB]=pHst(X,nB,Clr,LinWdt);
% X n x 1 data
% nB 1 x 1 number of bins
% Clr 1 x 1 single character MATLAB colour, or colour character + line
% style characters
% LinWdt 1 x 1 MATLAB line width
if nargin==0;
fprintf(1,'Test case\n');
X=randn(100,1);
nB=10;
Clr='k';
LinWdt=1;
elseif nargin==1;
nB=100;
Clr='k';
LinWdt=1;
elseif nargin==2;
Clr='k';
LinWdt=1;
elseif nargin==3;
LinWdt=1;
end;
if isempty(X)==0;
%generate basic histogram
if range(X)<eps;
fprintf(1,'Warning: pltHst: range of X near zero\n');
a=mean(X);
if abs(X)>eps;
tRng=linspace(0.9*a,1.1*a,nB);
else;
tRng=linspace(a-1,a+1,nB);
end;
else;
tRng=linspace(min(X),max(X),nB);
end;
tB=hist(X,tRng);
tB=tB/(sum(tB)*(tRng(2)-tRng(1)));
hold on;
h=bar(tRng,tB,'hist');
if length(Clr)==1;
set(h,'FaceAlpha',0,'LineWidth',LinWdt,'EdgeColor',Clr(1));
else;
set(h,'FaceAlpha',0,'LineWidth',LinWdt,'EdgeColor',Clr(1),'LineStyle',Clr(2:end));
end;
end;
return