~ubuntu-branches/debian/sid/octave3.0/sid

« back to all changes in this revision

Viewing changes to scripts/plot/hist.m

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Weber
  • Date: 2008-08-12 22:28:01 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080812222801-b3myaxymt2k5m709
Tags: 1:3.0.1-6lenny1
Allow libhdf5-openmpi-dev to satisfy Octave's hdf5 dependency (closes:
#494139)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
## Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2002, 2003,
2
 
##               2004, 2005, 2006, 2007 John W. Eaton
 
2
##               2004, 2005, 2006, 2007, 2008 John W. Eaton
3
3
##
4
4
## This file is part of Octave.
5
5
##
97
97
 
98
98
  cutoff = (x(1:end-1,:) + x(2:end,:)) / 2;
99
99
  n = rows (x);
 
100
  y_nc = columns (y);
100
101
  if (n < 30 && columns (x) == 1)
101
102
    ## The following algorithm works fastest for n less than about 30.
102
 
    chist = zeros (n+1, columns (y));
 
103
    chist = zeros (n+1, y_nc);
103
104
    for i = 1:n-1
104
105
      chist(i+1,:) = sum (y <= cutoff(i));
105
106
    endfor
108
109
    ## The following algorithm works fastest for n greater than about 30.
109
110
    ## Put cutoff elements between boundaries, integrate over all
110
111
    ## elements, keep totals at boundaries.
111
 
    [s, idx] = sort ([y; cutoff]);
 
112
    [s, idx] = sort ([y; repmat(cutoff, 1, y_nc)]);
112
113
    len = rows (y);
113
114
    chist = cumsum (idx <= len);
114
 
    t1 = zeros (1, columns (y));
115
 
    t2 = reshape (chist(idx > len), size (cutoff));
116
 
    t3 = chist(end,:) - sum (isnan (y));
117
 
    chist = [t1; t2; t3];
 
115
    chist = [(zeros (1, y_nc));
 
116
             (reshape (chist(idx > len), rows (cutoff), y_nc));
 
117
             (chist(end,:) - sum (isnan (y)))];
118
118
  endif
119
119
 
120
120
  freq = diff (chist);
166
166
%!    assert( sum(hist([1:n], 29)), n);
167
167
%!    assert( sum(hist([1:n], 30)), n);
168
168
%!  endfor
 
169
%!test
 
170
%!  assert (size (hist(randn(750,240), 200)), [200,240]);