Skip to content
Snippets Groups Projects
Commit c68828c4 authored by marwan's avatar marwan
Browse files

bug fix for empty vector

parent 2ed15213
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,9 @@ function e=entropy(x)
% $Revision$
%
% $Log$
% Revision 2.3 2009/03/24 08:32:09 marwan
% copyright address changed
%
% Revision 2.2 2005/04/06 12:58:08 marwan
% changed from log2 to natural log
%
......@@ -32,8 +35,13 @@ function e=entropy(x)
error(nargchk(1,1,nargin));
if nargout>1, error('Too many output arguments'), end
for j=1:size(x,2);
x(:,j)=x(:,j)./sum(x(:,j));
x2=x(find(x(:,j)),j);
e(:,j)=sum(-x2.*log(x2));
if isempty(x)
e = 0;
else
for j=1:size(x,2);
x(:,j)=x(:,j)./sum(x(:,j));
x2=x(find(x(:,j)),j);
e(:,j)=sum(-x2.*log(x2));
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment