This is a static copy of a profile reportHome
chckxywp (404 calls, 0.180 sec)
Generated 05-Nov-2014 07:53:25 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/curvefit/splines/chckxywp.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 |
68 | nanx = find(~isfinite(x)); | 404 | 0.030 s | 16.7% |  |
140 | if ~isempty(nanx), y(nanx,:) =... | 404 | 0.020 s | 11.1% |  |
100 | if nargin>2&&~nmin ... | 404 | 0.020 s | 11.1% |  |
86 | yn = sizeval(end); sizeval(end... | 404 | 0.020 s | 11.1% |  |
209 | origint = []; % this will be s... | 202 | 0.010 s | 5.6% |  |
All other lines | | | 0.080 s | 44.4% |  |
Totals | | | 0.180 s | 100% | |
Children (called functions)
No childrenCode Analyzer results
Line number | Message |
1 | Input argument 'adjtol' might be unused. If this is OK, consider replacing it by ~. |
167 | Extra comma is unnecessary. |
184 | IF might not be aligned with its matching END (line 186). |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 227 |
Non-code lines (comments, blank lines) | 98 |
Code lines (lines that can run) | 129 |
Code lines that did run | 44 |
Code lines that did not run | 85 |
Coverage (did run/can run) | 34.11 % |
Function listing
time calls line
1 function [x,y,sizeval,w,origint,p,tolred] = chckxywp(x,y,nmin,w,p,adjtol)
2 %CHCKXYWP Check and adjust input for *AP*1 commands.
3 %
4 % [X,Y,SIZEVAL] = CHCKXYWP(X,Y) is used in CSAPI1 to check
5 % the data sites X and corresponding data values Y,
6 % making certain that there are exactly as many sites as values,
7 % and at least NMIN = 2 data points, and also reshaping Y, if need be,
8 % into a matrix, returning in SIZEVAL the original size of a data value,
9 % also removing any data points that involve NaNs or Infs, also
10 % dropping the imaginary part, if any, of any data site, also
11 % reordering the points if necessary to ensure that X is nondecreasing,
12 % and then averaging any data points with the same site, thus making sure
13 % that X is strictly increasing.
14 % Only if all these tests are passed, are the data, perhaps modified,
15 % returned, with X of size [n,1], and Y of size [n,prod(SIZEVAL)].
16 %
17 % [X,Y,SIZEVAL,VALCONDS] = CHCKXYWP(X,Y,0) is used in CSAPE1.
18 % It differs from the preceding call in that it permits the possibility
19 % of there being 2 more data values than there are sites and, in that case,
20 % strips off the first and last data value, returning it separately in
21 % VALCONDS.
22 %
23 % [X,Y,SIZEVAL] = CHCKXYWP(X,Y,NMIN) is used in SPAPI1.
24 % It differs from CHCKXYWP(X,Y) in that it makes certain that there are at
25 % least NMIN data points, and does not insist on the data sites all being
26 % different.
27 %
28 % [X,Y,SIZEVAL,W] = CHCKXYWP(X,Y,NMIN,W) is used in SPAP21.
29 % It differs from the preceding call in the following way.
30 % Any data points with the same data site are replaced by their weighted
31 % average while the corresponding entries of the weights W are summed.
32 % If W is empty, then the composite trapezoidal weights (corresponding
33 % to SORT(X)) are returned.
34 %
35 % [X,Y,SIZEVAL,W,ORIGINT,P] = CHCKXYWP(X,Y,NMIN,W,P) is used in CSAPS1.
36 % It differs from the preceding call in the following ways.
37 % Any data point (X(j),Y(:,j)) whose weight, W(j), is less than some small
38 % fraction of norm(W), is removed; if the leftmost and/or rightmost data
39 % point is removed in this way, then ORIGINT is the 1-by-2 matrix containing
40 % the site of the original leftmost and the original rightmost data point.
41 % Further, if length(P)>1, then any data point removal leads to the removal
42 % from P of the roughness weight for the interval to the left of that data
43 % site, -- except when a reordering of the data points was necessary, in
44 % which case all entries of P but the first are removed, i.e., the default
45 % roughness weights will be used.
46 %
47 % [X,Y,SIZEVAL,W,ORIGINT,TOL,TOLRED] = CHCKXYWP(X,Y,NMIN,W,TOL,ADJTOL) is
48 % used in SPAPS1. It differs from the preceding call in that it also returns,
49 % in TOLRED, the amount by which the error measure is reduced due to the
50 % replacement of any data points with the same site by their average.
51 %
52 % See also CSAPI, SPAPI, SPAP2, CSAPS, SPAPS.
53
54 % Copyright 1984-2010 The MathWorks, Inc.
55 % $Revision: 1.1.6.4 $ $Date: 2011/05/09 00:40:22 $
56
57 % make sure X is a vector:
0.01 404 58 if iscell(x)||length(find(size(x)>1))>1
59 error(message('SPLINES:CHCKXYWP:Xnotvec')), end
60
61 % make sure X is real:
0.01 404 62 if ~all(isreal(x))
63 x = real(x);
64 warning(message('SPLINES:CHCKXYWP:Xnotreal'))
65 end
66
67 % deal with NaN's and Inf's among the sites:
0.03 404 68 nanx = find(~isfinite(x));
404 69 if ~isempty(nanx)
70 x(nanx) = [];
71 warning(message('SPLINES:CHCKXYWP:NaNs'))
72 end
73
404 74 n = length(x);
0.01 404 75 if nargin>2&&nmin>0, minn = nmin; else minn = 2; end
404 76 if n<minn
77 error(message('SPLINES:CHCKXYWP:toofewpoints', sprintf( '%g', minn ))), end
78
79 % re-sort, if needed, to ensure nondecreasing site sequence:
404 80 tosort = false;
0.01 404 81 if any(diff(x)<0), tosort = true; [x,ind] = sort(x); end
82
404 83 nstart = n+length(nanx);
84 % if Y is ND, reshape it to a matrix by combining all dimensions but the last:
404 85 sizeval = size(y);
0.02 404 86 yn = sizeval(end); sizeval(end) = []; yd = prod(sizeval);
404 87 if length(sizeval)>1
88 y = reshape(y,yd,yn);
404 89 else
90 % if Y happens to be a column matrix, of the same length as the original X,
91 % then change Y to a row matrix
404 92 if yn==1&&yd==nstart
93 yn = yd; y = reshape(y,1,yn); yd = 1; sizeval = yd;
94 end
404 95 end
0.01 404 96 y = y.'; x = reshape(x,n,1);
97
98 % make sure that sites, values and weights match in number:
99
0.02 404 100 if nargin>2&&~nmin % in this case we accept two more data values than
101 % sites, stripping off the first and last, and returning
102 % them separately, in W, for use in CSAPE1.
103 switch yn
104 case nstart+2, w = y([1 end],:); y([1 end],:) = [];
105 if ~all(isfinite(w)),
106 error(message('SPLINES:CHCKXYWP:InfY'))
107 end
108 case nstart, w = [];
109 otherwise
110 error(message('SPLINES:CHCKXYWP:XdontmatchY', sprintf( '%g', nstart ), sprintf( '%g', yn )))
111 end
404 112 else
404 113 if yn~=nstart
114 error(message('SPLINES:CHCKXYWP:XdontmatchY', sprintf( '%g', nstart ), sprintf( '%g', yn )))
115 end
404 116 end
117
404 118 nonemptyw = nargin>3&&~isempty(w);
404 119 if nonemptyw
202 120 if length(w)~=nstart
121 error(message('SPLINES:CHCKXYWP:weightsdontmatchX', sprintf( '%g', length( w ) ), sprintf( '%g', nstart )))
202 122 else
202 123 w = reshape(w,1,nstart);
202 124 end
202 125 end
126
0.01 404 127 roughnessw = exist('p','var')&&length(p)>1;
404 128 if roughnessw
129 if tosort
130 warning(message('SPLINES:CHCKXYWP:cantreorderrough'))
131 p = p(1);
132 else
133 if length(p)~=nstart
134 error(message('SPLINES:CHCKXYWP:rweightsdontmatchX', sprintf( '%g', nstart )))
135 end
136 end
137 end
138
139 %%% remove values and error weights corresponding to nonfinite sites:
0.02 404 140 if ~isempty(nanx), y(nanx,:) = []; if nonemptyw, w(nanx) = []; end
141 if roughnessw % as a first approximation, simply ignore the
142 % specified weight to the left of any ignored point.
143 p(max(nanx,2)) = [];
144 end
145 end
404 146 if tosort, y = y(ind,:); if nonemptyw, w = w(ind); end, end
147
148 % deal with nonfinites among the values:
0.01 404 149 nany = find(sum(~isfinite(y),2));
0.01 404 150 if ~isempty(nany)
151 y(nany,:) = []; x(nany) = []; if nonemptyw, w(nany) = []; end
152 warning(message('SPLINES:CHCKXYWP:NaNs'))
153 n = length(x);
154 if n<minn
155 error(message('SPLINES:CHCKXYWP:toofewX', sprintf( '%g', minn ))), end
156 if roughnessw % as a first approximation, simply ignore the
157 % specified weight to the left of any ignored point.
158 p(max(nany,2)) = [];
159 end
160 end
161
404 162 if nargin==3&&nmin, return, end % for SPAPI, skip the averaging
163
202 164 if nargin>3&&isempty(w) % use the trapezoidal rule weights:
165 dx = diff(x);
166 if any(dx), w = ([dx;0]+[0;dx]).'/2;
167 else, w = ones(1,n);
168 end
169 nonemptyw = ~nonemptyw;
170 end
171
202 172 tolred = 0;
202 173 if ~all(diff(x)) % conflate repeat sites, averaging the corresponding values
174 % and summing the corresponding weights
175 mults = knt2mlt(x);
176 for j=find(diff([mults;0])<0).'
177 if nonemptyw
178 temp = sum(w(j-mults(j):j));
179 if nargin>5
180 tolred = tolred + w(j-mults(j):j)*sum(y(j-mults(j):j,:).^2,2);
181 end
182 y(j-mults(j),:) = (w(j-mults(j):j)*y(j-mults(j):j,:))/temp;
183 w(j-mults(j)) = temp;
184 if nargin>5
185 tolred = tolred - temp*sum(y(j-mults(j),:).^2);
186 end
187 else
188 y(j-mults(j),:) = mean(y(j-mults(j):j,:),1);
189 end
190 end
191
192 repeats = find(mults);
193 x(repeats) = []; y(repeats,:) = []; if nonemptyw, w(repeats) = []; end
194 if roughnessw % as a first approximation, simply ignore the
195 % specified weight to the left of any ignored point.
196 p(max(repeats,2)) = [];
197 end
198 n = length(x);
199 if n<minn, error(message('SPLINES:CHCKXYWP:toofewX', sprintf( '%g', minn ))), end
200 end
201
202 202 if nargin<4, return, end
203
204
205 % remove all points corresponding to relatively small weights (since a
206 % (near-)zero weight in effect asks for the corresponding datum to be dis-
207 % regarded while, at the same time, leading to bad condition and even
208 % division by zero).
0.01 202 209 origint = []; % this will be set to x([1 end]).' in case the weight for an end
210 % data point is near zero, hence the approximation is computed
211 % without that endpoint.
202 212 if nonemptyw
202 213 ignorep = find( w <= (1e-13)*max(abs(w)) );
202 214 if ~isempty(ignorep)
215 if ignorep(1)==1||ignorep(end)==n, origint = x([1 end]).'; end
216 x(ignorep) = []; y(ignorep,:) = []; w(ignorep) = [];
217 if roughnessw
218 % as a first approximation, simply ignore the
219 % specified weight to the left of any ignored point.
220 p(max(ignorep,2)) = [];
221 end
222 n = length(x);
223 if n<minn
224 error(message('SPLINES:CHCKXYWP:toofewposW', sprintf( '%g', minn )))
225 end
226 end
202 227 end