Mercurial > octave-libgccjit
comparison scripts/statistics/base/histc.m @ 8937:f27b2c95817f
slightly simplify histc
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Mon, 09 Mar 2009 16:03:17 +0100 |
parents | cae073411b03 |
children | 1bf0ce0930be |
comparison
equal
deleted
inserted
replaced
8936:42e24f4ebc8c | 8937:f27b2c95817f |
---|---|
75 endif | 75 endif |
76 else | 76 else |
77 error ("histc: second argument must be a vector"); | 77 error ("histc: second argument must be a vector"); |
78 endif | 78 endif |
79 | 79 |
80 ## Allocate the histogram | |
81 nsz = sz; | 80 nsz = sz; |
82 nsz (dim) = num_edges; | 81 nsz (dim) = num_edges; |
83 n = zeros (nsz); | |
84 | 82 |
85 ## the splitting point is 3 bins | 83 ## the splitting point is 3 bins |
86 | 84 |
87 if (num_edges <= 3) | 85 if (num_edges <= 3) |
88 | 86 |
89 ## This is the O(M*N) algorithm. | 87 ## This is the O(M*N) algorithm. |
88 | |
89 ## Allocate the histogram | |
90 n = zeros (nsz); | |
90 | 91 |
91 ## Allocate 'idx' | 92 ## Allocate 'idx' |
92 if (nargout > 1) | 93 if (nargout > 1) |
93 idx = zeros (sz); | 94 idx = zeros (sz); |
94 endif | 95 endif |
145 | 146 |
146 ## Select valid elements. | 147 ## Select valid elements. |
147 iidx = iidx(idx != 0); | 148 iidx = iidx(idx != 0); |
148 | 149 |
149 ## Call accumarray to sum the indexed elements. | 150 ## Call accumarray to sum the indexed elements. |
150 sz(dim) = length (edges); | 151 n = accumarray (iidx(:), 1, nsz); |
151 n = accumarray (iidx(:), 1, sz); | |
152 | 152 |
153 endif | 153 endif |
154 | 154 |
155 endfunction | 155 endfunction |
156 | 156 |