This is a static copy of a profile reportHome
smooth (30 calls, 1.148 sec)
Generated 05-Aug-2011 13:03:49 using cpu time.
function in file /home/LeechJ/cbass_analysis/matutils/smooth.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
165 | c(ok) = moving(x(ok),y(ok),spa... | 30 | 0.547 s | 47.6% |  |
137 | if uniformx(diffx,x,y) | 30 | 0.186 s | 16.2% |  |
155 | sortx = any(diff(isnan(x))<... | 30 | 0.087 s | 7.6% |  |
192 | c(idx) = c; | 30 | 0.077 s | 6.7% |  |
156 | if sortx || any(diff(x)<0) ... | 30 | 0.077 s | 6.7% |  |
All other lines | | | 0.175 s | 15.2% |  |
Totals | | | 1.148 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
smooth>moving | subfunction | 30 | 0.404 s | 35.2% |  |
smooth>uniformx | subfunction | 30 | 0.175 s | 15.2% |  |
Self time (built-ins, overhead, etc.) | | | 0.568 s | 49.5% |  |
Totals | | | 1.148 s | 100% | |
Code Analyzer results
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 198 |
Non-code lines (comments, blank lines) | 97 |
Code lines (lines that can run) | 101 |
Code lines that did run | 40 |
Code lines that did not run | 61 |
Coverage (did run/can run) | 39.60 % |
Function listing
time calls line
1 function [c,ww] = smooth(varargin)
2 %SMOOTH Smooth data.
3 % Z = SMOOTH(Y) smooths data Y using a 5-point moving average.
4 %
5 % Z = SMOOTH(Y,SPAN) smooths data Y using SPAN as the number of points used
6 % to compute each element of Z.
7 %
8 % Z = SMOOTH(Y,SPAN,METHOD) smooths data Y with specified METHOD. The
9 % available methods are:
10 %
11 % 'moving' - Moving average (default)
12 % 'lowess' - Lowess (linear fit)
13 % 'loess' - Loess (quadratic fit)
14 % 'sgolay' - Savitzky-Golay
15 % 'rlowess' - Robust Lowess (linear fit)
16 % 'rloess' - Robust Loess (quadratic fit)
17 %
18 % Z = SMOOTH(Y,METHOD) uses the default SPAN 5.
19 %
20 % Z = SMOOTH(Y,SPAN,'sgolay',DEGREE) and Z = SMOOTH(Y,'sgolay',DEGREE)
21 % additionally specify the degree of the polynomial to be used in the
22 % Savitzky-Golay method. The default DEGREE is 2. DEGREE must be smaller
23 % than SPAN.
24 %
25 % Z = SMOOTH(X,Y,...) additionally specifies the X coordinates. If X is
26 % not provided, methods that require X coordinates assume X = 1:N, where
27 % N is the length of Y.
28 %
29 % Notes:
30 % 1. When X is given and X is not uniformly distributed, the default method
31 % is 'lowess'. The 'moving' method is not recommended.
32 %
33 % 2. For the 'moving' and 'sgolay' methods, SPAN must be odd.
34 % If an even SPAN is specified, it is reduced by 1.
35 %
36 % 3. If SPAN is greater than the length of Y, it is reduced to the
37 % length of Y.
38 %
39 % 4. In the case of (robust) lowess and (robust) loess, it is also
40 % possible to specify the SPAN as a percentage of the total number
41 % of data points. When SPAN is less than or equal to 1, it is
42 % treated as a percentage.
43 %
44 % For example:
45 %
46 % Z = SMOOTH(Y) uses the moving average method with span 5 and
47 % X=1:length(Y).
48 %
49 % Z = SMOOTH(Y,7) uses the moving average method with span 7 and
50 % X=1:length(Y).
51 %
52 % Z = SMOOTH(Y,'sgolay') uses the Savitzky-Golay method with DEGREE=2,
53 % SPAN = 5, X = 1:length(Y).
54 %
55 % Z = SMOOTH(X,Y,'lowess') uses the lowess method with SPAN=5.
56 %
57 % Z = SMOOTH(X,Y,SPAN,'rloess') uses the robust loess method.
58 %
59 % Z = SMOOTH(X,Y) where X is unevenly distributed uses the
60 % 'lowess' method with span 5.
61 %
62 % Z = SMOOTH(X,Y,8,'sgolay') uses the Savitzky-Golay method with
63 % span 7 (8 is reduced by 1 to make it odd).
64 %
65 % Z = SMOOTH(X,Y,0.3,'loess') uses the loess method where span is
66 % 30% of the data, i.e. span = ceil(0.3*length(Y)).
67 %
68 % See also SPLINE.
69
70 % Copyright 2001-2009 The MathWorks, Inc.
71 % $Revision: 1.1 $ $Date: 2010/09/15 10:04:55 $
72
30 73 if nargin < 1
74 error('curvefit:smooth:needMoreArgs', ...
75 'SMOOTH needs at least one argument.');
76 end
77
30 78 if nargout > 1 % Called from the GUI cftool
79 ws = warning('off', 'all'); % turn warning off and record the previous warning state.
80 [lw,lwid] = lastwarn;
81 lastwarn('');
30 82 else
30 83 ws = warning('query','all'); % Leave warning state alone but save it so resets are no-ops.
0.01 30 84 end
85
86 % is x given as the first argument?
30 87 if nargin==1 || ( nargin > 1 && (length(varargin{2})==1 || ischar(varargin{2})) )
88 % smooth(Y) | smooth(Y,span,...) | smooth(Y,method,...)
30 89 is_x = 0; % x is not given
30 90 y = varargin{1};
30 91 y = y(:);
0.03 30 92 x = (1:length(y))';
93 else % smooth(X,Y,...)
94 is_x = 1;
95 y = varargin{2};
96 x = varargin{1};
97 y = y(:);
98 x = x(:);
99 end
100
101 % is span given?
30 102 span = [];
30 103 if nargin == 1+is_x || ischar(varargin{2+is_x})
104 % smooth(Y), smooth(X,Y) || smooth(X,Y,method,..), smooth(Y,method)
6 105 is_span = 0;
24 106 else
107 % smooth(...,SPAN,...)
24 108 is_span = 1;
24 109 span = varargin{2+is_x};
24 110 end
111
112 % is method given?
30 113 method = [];
0.01 30 114 if nargin >= 2+is_x+is_span
115 % smooth(...,Y,method,...) | smooth(...,Y,span,method,...)
116 method = varargin{2+is_x+is_span};
117 end
118
30 119 t = length(y);
30 120 if t == 0
121 c = y;
122 ww = '';
123 if nargout > 1
124 ww = lastwarn;
125 lastwarn(lw,lwid);
126 warning(ws); % turn warning back to the previous state.
127 end
128 return
30 129 elseif length(x) ~= t
130 warning(ws); % reset warn state before erroring
131 error('curvefit:smooth:XYmustBeSameLength',...
132 'X and Y must be the same length.');
133 end
134
30 135 if isempty(method)
0.03 30 136 diffx = diff(x);
0.19 30 137 if uniformx(diffx,x,y)
30 138 method = 'moving'; % uniformly distributed X.
139 else
140 method = 'lowess';
141 end
30 142 end
143
144 % realize span
30 145 if span <= 0
146 warning(ws); % reset warn state before erroring
147 error('curvefit:smooth:spanMustBePositive', ...
148 'SPAN must be positive.');
149 end
30 150 if span < 1, span = ceil(span*t); end % percent convention
30 151 if isempty(span), span = 5; end % smooth(Y,[],method)
152
0.03 30 153 idx = 1:t;
154
0.09 30 155 sortx = any(diff(isnan(x))<0); % if NaNs not all at end
0.08 30 156 if sortx || any(diff(x)<0) % sort x
157 [x,idx] = sort(x);
158 y = y(idx);
159 end
160
30 161 c = NaN(size(y));
0.04 30 162 ok = ~isnan(x);
30 163 switch method
30 164 case 'moving'
0.55 30 165 c(ok) = moving(x(ok),y(ok),span);
166 case {'lowess','loess','rlowess','rloess'}
167 robust = 0;
168 iter = 5;
169 if method(1)=='r'
170 robust = 1;
171 method = method(2:end);
172 end
173 c(ok) = lowess(x(ok),y(ok),span, method,robust,iter);
174 case 'sgolay'
175 if nargin >= 3+is_x+is_span
176 degree = varargin{3+is_x+is_span};
177 else
178 degree = 2;
179 end
180 if degree < 0 || degree ~= floor(degree) || degree >= span
181 warning(ws); % reset warn state before erroring
182 error('curvefit:smooth:invalidDegree', ...
183 'Degree must be an integer between 0 and span-1.');
184 end
185 c(ok) = sgolay(x(ok),y(ok),span,degree);
186 otherwise
187 warning(ws); % reset warn state before erroring
188 error('curvefit:smooth:unrecognizedMethod', ...
189 'SMOOTH: Unrecognized method.');
190 end
191
0.08 30 192 c(idx) = c;
193
30 194 if nargout > 1
195 ww = lastwarn;
196 lastwarn(lw,lwid);
197 warning(ws); % turn warning back to the previous state.
198 end
Other subfunctions in this file are not included in this listing.