# HG changeset patch # User schloegl # Date 1411432757 0 # Node ID 3d8947eadc0e836f9fa9e10939519f1cbcb40a65 # Parent 78e73ee34c889e3e7ca99d6839fac5e0c6c947b1 histo[234]: empty imput is supported, add tests diff -r 78e73ee34c88 -r 3d8947eadc0e extra/tsa/inst/histo2.m --- a/extra/tsa/inst/histo2.m Thu Sep 18 14:59:30 2014 +0000 +++ b/extra/tsa/inst/histo2.m Tue Sep 23 00:39:17 2014 +0000 @@ -26,7 +26,7 @@ % C.E. Shannon and W. Weaver "The mathematical theory of communication" University of Illinois Press, Urbana 1949 (reprint 1963). % $Id$ -% Copyright (C) 1996-2002,2008,2011 by Alois Schloegl +% Copyright (C) 1996-2002,2008,2011,2014 by Alois Schloegl % This is part of the TSA-toolbox % http://pub.ist.ac.at/~schloegl/matlab/tsa/ % @@ -55,6 +55,11 @@ %%%%% identify all possible X's and generate overall Histogram %%%%% N = sum(~isnan(Y), 1); +if all(N==0) + H=[]; + X=[]; +end; + NN = N; if isempty(W) sY = sort(Y,1); @@ -95,3 +100,7 @@ R.X = X; R.N = NN; +%!assert(getfield(histo2([]),'N'), 0) +%!assert(getfield(histo2(1),'N'), 1) +%!assert(getfield(histo2([1;1]),'H'), 2) + diff -r 78e73ee34c88 -r 3d8947eadc0e extra/tsa/inst/histo3.m --- a/extra/tsa/inst/histo3.m Thu Sep 18 14:59:30 2014 +0000 +++ b/extra/tsa/inst/histo3.m Tue Sep 23 00:39:17 2014 +0000 @@ -35,7 +35,7 @@ % $Id$ -% Copyright (C) 1996-2002,2008,2011 by Alois Schloegl +% Copyright (C) 1996-2002,2008,2011,2014 by Alois Schloegl % This is part of the TSA-toolbox. See also % http://pub.ist.ac.at/~schloegl/matlab/tsa/ % http://octave.sourceforge.net/ @@ -72,8 +72,13 @@ tmp = [find(ix); sum(~isnan(sY))]; R.datatype = 'HISTOGRAM'; +R.N = sum(~isnan(Y), 1); +if all(R.N==0) + R.X=[]; + R.H=[]; + return; +end; R.X = sY(tmp); -R.N = sum(~isnan(Y), 1); % generate inverse index if nargout>1, @@ -150,4 +155,7 @@ R.H = H; end; +%!assert(getfield(histo3([]),'N'), 0) +%!assert(getfield(histo3(1),'N'), 1) +%!assert(getfield(histo3([1;1]),'H'), 2) diff -r 78e73ee34c88 -r 3d8947eadc0e extra/tsa/inst/histo4.m --- a/extra/tsa/inst/histo4.m Thu Sep 18 14:59:30 2014 +0000 +++ b/extra/tsa/inst/histo4.m Tue Sep 23 00:39:17 2014 +0000 @@ -28,7 +28,7 @@ % $Id$ -% Copyright (C) 1996-2005,2008,2009,2011 by Alois Schloegl +% Copyright (C) 1996-2005,2008,2009,2011,2014 by Alois Schloegl % This is part of the TSA-toolbox % http://pub.ist.ac.at/~schloegl/matlab/tsa/ % @@ -54,6 +54,13 @@ if ~isempty(W) && (yr ~= numel(W)), error('number of rows of Y does not match number of elements in W'); end; +R.datatype = 'HISTOGRAM'; +if isempty(Y) + R.N = 0; + R.X = zeros(size(Y)); + R.H = []; + return +end %%%%% identify all possible X's and generate overall Histogram %%%%% [Y, idx] = sortrows(Y); @@ -63,7 +70,6 @@ tmp = [find(ix); yr]; R.X = Y(tmp,:); -R.datatype = 'HISTOGRAM'; if isempty(W) R.H = [tmp(1); diff(tmp)]; R.N = yr; @@ -95,3 +101,7 @@ R.tix = tix; end; +%!assert(getfield(histo4([]),'N'), 0) +%!assert(getfield(histo4(1),'N'), 1) +%!assert(getfield(histo4([1;1]),'H'), 2) +