This is a static copy of a profile report

Home

smooth>moving (30 calls, 0.404 sec)
Generated 05-Aug-2011 13:03:50 using cpu time.
subfunction in file /home/LeechJ/cbass_analysis/matutils/smooth.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
smoothfunction30
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
213
c = filter(ones(width,1)/width...
300.175 s43.2%
209
xreps = any(diff(x)==0);
300.087 s21.6%
218
c = [cbegin;c(width:end);cend]...
300.077 s18.9%
204
ynan = isnan(y);
300.022 s5.4%
215
cbegin = cbegin(1:2:end)./(1:2...
300.011 s2.7%
All other lines  0.033 s8.1%
Totals  0.404 s100% 
Children (called functions)
No children
Code Analyzer results
Line numberMessage
Coverage results
[ Show coverage for parent directory ]
Total lines in function54
Non-code lines (comments, blank lines)6
Code lines (lines that can run)48
Code lines that did run14
Code lines that did not run34
Coverage (did run/can run)29.17 %
Function listing
   time   calls  line
201 function c = moving(x,y, span)
202 % moving average of the data.
203
0.02 30 204 ynan = isnan(y);
30 205 span = floor(span);
30 206 n = length(y);
30 207 span = min(span,n);
30 208 width = span-1+mod(span,2); % force it to be odd
0.09 30 209 xreps = any(diff(x)==0);
30 210 if width==1 && ~xreps && ~any(ynan), c = y; return; end
30 211 if ~xreps && ~any(ynan)
212 % simplest method for most common case
0.17 30 213 c = filter(ones(width,1)/width,1,y);
30 214 cbegin = cumsum(y(1:width-2));
0.01 30 215 cbegin = cbegin(1:2:end)./(1:2:(width-2))';
30 216 cend = cumsum(y(n:-1:n-width+3));
30 217 cend = cend(end:-2:1)./(width-2:-2:1)';
0.08 30 218 c = [cbegin;c(width:end);cend];
219 elseif ~xreps
220 % with no x repeats, can take ratio of two smoothed sequences
221 yy = y;
222 yy(ynan) = 0;
223 nn = double(~ynan);
224 ynum = moving(x,yy,span);
225 yden = moving(x,nn,span);
226 c = ynum ./ yden;
227 else
228 % with some x repeats, loop
229 notnan = ~ynan;
230 yy = y;
231 yy(ynan) = 0;
232 c = zeros(n,1);
233 for i=1:n
234 if i>1 && x(i)==x(i-1)
235 c(i) = c(i-1);
236 continue;
237 end
238 R = i; % find rightmost value with same x
239 while(R<n && x(R+1)==x(R))
240 R = R+1;
241 end
242 hf = ceil(max(0,(span - (R-i+1))/2)); % need this many more on each side
243 hf = min(min(hf,(i-1)), (n-R));
244 L = i-hf; % find leftmost point needed
245 while(L>1 && x(L)==x(L-1))
246 L = L-1;
247 end
248 R = R+hf; % find rightmost point needed
249 while(R<n && x(R)==x(R+1))
250 R = R+1;
251 end
252 c(i) = sum(yy(L:R)) / sum(notnan(L:R));
253 end
254 end

Other subfunctions in this file are not included in this listing.