⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 histo.m

📁 时间序列工具箱
💻 M
字号:
function [H,X,E]=histo(Y,N)
% [H,X]=HISTO(Y,N)
% 	Calculates histogram with fixed binwidth N (default N=1). 
% HISTO(Y,N) 
%	plots the histogram bar(X,H)
% [H,X,E]=HISTO(Y,N)            
%	calculates also the Entropy E of Y with respect of binwidth N

%	Version 2.44
%	last revision 22.06.1998
%	Copyright (c) 1997-1998 by Alois Schloegl
%	e-mail: a.schloegl@ieee.org	

% This library is free software; you can redistribute it and/or
% modify it under the terms of the GNU Library General Public
% License as published by the Free Software Foundation; either
% Version 2 of the License, or (at your option) any later version.
%
% This library is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
% Library General Public License for more details.
%
% You should have received a copy of the GNU Library General Public
% License along with this library; if not, write to the
% Free Software Foundation, Inc., 59 Temple Place - Suite 330,
% Boston, MA  02111-1307, USA.

if nargin<2 N=1; end;

M=length(Y);
        % ROUND Data
Y=round(Y(:)/N); 
X=(min(Y):max(Y))*N;
        % transform range of Y to 1..max(Y)
Y=Y+1-min(Y);

H=zeros(max(Y),1);
for k=1:M, H(Y(k))=H(Y(k))+1; end;      % Octave

% H=full(sparse(Y,1,1,length(X),1));    % Matlab 4.x, H must not be sparse in bar(X,H)
% H=sparse(Y,1,1,length(X),1);          % Matlab 5.x

% Sorted Data       % find k where Y(k) is different to Y(k-1)
% Y=sort(Y);        k=find([1; diff(Y)]>0);        H(Y(k))=diff([k; length(Y)+1]);
        
if nargout == 0
    	bar(X,H);
elseif nargout==3
	% calculates ENTROPY = sum(p(i)*log(p(i))) with p(i)=H/M;
	p=H(find(H))/M;
	E=-sum(p.*log(p))/log(2);
end;
                                    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -