Mercurial > hg > octave-shane
changeset 11675:20244a1412cb release-3-0-x
hist: avoid temps; allow matrix args when number of bins > 30
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 06 Mar 2008 13:42:08 -0500 |
parents | 270677feba91 |
children | 6467c8a9175a |
files | scripts/ChangeLog scripts/plot/hist.m |
diffstat | 2 files changed, 12 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,9 @@ 2008-03-06 John W. Eaton <jwe@octave.org> + * plot/hist.m: Avoid temporaries. + Allow matrix arguments when number of bins > 30. + From Robert S. Mahurin <mahurin@fiver.phys.utk.edu>. + * plot/__go_draw_axes__.m: Adjust markersize by a factor of 1/6. 2008-03-05 Ben Abbott <bpabbott@mac.com>
--- a/scripts/plot/hist.m +++ b/scripts/plot/hist.m @@ -97,9 +97,10 @@ cutoff = (x(1:end-1,:) + x(2:end,:)) / 2; n = rows (x); + y_nc = columns (y); if (n < 30 && columns (x) == 1) ## The following algorithm works fastest for n less than about 30. - chist = zeros (n+1, columns (y)); + chist = zeros (n+1, y_nc); for i = 1:n-1 chist(i+1,:) = sum (y <= cutoff(i)); endfor @@ -108,13 +109,12 @@ ## The following algorithm works fastest for n greater than about 30. ## Put cutoff elements between boundaries, integrate over all ## elements, keep totals at boundaries. - [s, idx] = sort ([y; cutoff]); + [s, idx] = sort ([y; repmat(cutoff, 1, y_nc)]); len = rows (y); chist = cumsum (idx <= len); - t1 = zeros (1, columns (y)); - t2 = reshape (chist(idx > len), size (cutoff)); - t3 = chist(end,:) - sum (isnan (y)); - chist = [t1; t2; t3]; + chist = [(zeros (1, y_nc)); + (reshape (chist(idx > len), rows (cutoff), y_nc)); + (chist(end,:) - sum (isnan (y)))]; endif freq = diff (chist); @@ -166,3 +166,5 @@ %! assert( sum(hist([1:n], 29)), n); %! assert( sum(hist([1:n], 30)), n); %! endfor +%!test +%! assert (size (hist(randn(750,240), 200)), [200,240]);