# HG changeset patch # User John W. Eaton # Date 1204828928 18000 # Node ID b3acdf1c41a52562b0f878e9c25339c95f4aaebc # Parent 1e6443ff960f980a6289d9cdec4080d917e51189 hist: avoid temps; allow matrix args when number of bins > 30 diff -r 1e6443ff960f -r b3acdf1c41a5 scripts/ChangeLog --- a/scripts/ChangeLog Thu Mar 06 13:28:02 2008 -0500 +++ b/scripts/ChangeLog Thu Mar 06 13:42:08 2008 -0500 @@ -1,5 +1,9 @@ 2008-03-06 John W. Eaton + * plot/hist.m: Avoid temporaries. + Allow matrix arguments when number of bins > 30. + From Robert S. Mahurin . + * plot/ChangeLog: Handle axes linewidth property. * plot/__go_draw_axes__.m: Adjust markersize by a factor of 1/6. diff -r 1e6443ff960f -r b3acdf1c41a5 scripts/plot/hist.m --- a/scripts/plot/hist.m Thu Mar 06 13:28:02 2008 -0500 +++ b/scripts/plot/hist.m Thu Mar 06 13:42:08 2008 -0500 @@ -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]);