changeset 12524:3d8947eadc0e octave-forge

histo[234]: empty imput is supported, add tests
author schloegl
date Tue, 23 Sep 2014 00:39:17 +0000
parents 78e73ee34c88
children 29a3da21f6df
files extra/tsa/inst/histo2.m extra/tsa/inst/histo3.m extra/tsa/inst/histo4.m
diffstat 3 files changed, 32 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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 <alois.schloegl@gmail.com>	
+%	Copyright (C) 1996-2002,2008,2011,2014 by Alois Schloegl <alois.schloegl@ist.ac.at>	
 %    	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)
+
--- 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 <a.schloegl@ieee.org>	
+%	Copyright (C) 1996-2002,2008,2011,2014 by Alois Schloegl <alois.schloegl@ist.ac.at>	
 %       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)
 
--- 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 <alois.schloegl@gmail.com>	
+%	Copyright (C) 1996-2005,2008,2009,2011,2014 by Alois Schloegl <alois.schloegl@ist.ac.at>	
 %    	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)
+