diff scripts/statistics/base/mode.m @ 7287:3f29467c1667

[project @ 2007-12-11 17:03:32 by jwe]
author jwe
date Tue, 11 Dec 2007 17:03:33 +0000
parents a730e47fda4d
children 704b7a1098d0
line wrap: on
line diff
--- a/scripts/statistics/base/mode.m	Tue Dec 11 16:57:39 2007 +0000
+++ b/scripts/statistics/base/mode.m	Tue Dec 11 17:03:33 2007 +0000
@@ -84,7 +84,11 @@
   endif
 
   c = cell (sz2);
-  m = zeros (sz2);
+  if (issparse (x))
+    m = sparse (sz2(1), sz2(2));
+  else
+    m = zeros (sz2);
+  endif
   for i = 1 : prod (sz2)
     c{i} = xs (t2 (:, i) == f(i), i);
     m (i) = c{i}(1);
@@ -105,6 +109,6 @@
 %! a = sprandn (32, 32, 0.05);
 %! [m, f, c] = mode (a);
 %! [m2, f2, c2] = mode (full (a));
-%! assert (m, sparse (m2, 1));
-%! assert (f, sparse (f2, 1));
-%! assert (c, cellfun (@(x) sparse (1, 1), c2, 'UniformOutput', false));
+%! assert (m, sparse (m2));
+%! assert (f, sparse (f2));
+%! assert (c, cellfun (@(x) sparse (0), c2, 'UniformOutput', false));