This is a static copy of a profile reportHome
interp3 (417 calls, 379.545 sec)
Generated 05-Nov-2014 07:52:39 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/matlab/polyfun/interp3.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 |
136 | if (size(x,2)>1 && ... | 417 | 164.868 s | 43.4% |  |
225 | vi = linear(x,y,z,v,xi,yi,zi,E... | 417 | 101.150 s | 26.7% |  |
118 | [msg,x,y,z,v,xi,yi,zi] = xyzvc... | 417 | 101.150 s | 26.7% |  |
148 | xx = x(1,:,1).'; yy = y(:,1,1)... | 417 | 0.130 s | 0.0% |  |
135 | xx = x(1,:,1); yy = y(:,1,1); ... | 417 | 0.030 s | 0.0% |  |
All other lines | | | 12.217 s | 3.2% |  |
Totals | | | 379.545 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
repmat | function | 1251 | 105.456 s | 27.8% |  |
xyzvchk | function | 417 | 101.150 s | 26.7% |  |
interp3>linear | subfunction | 417 | 101.120 s | 26.6% |  |
squeeze | function | 417 | 0.070 s | 0.0% |  |
Self time (built-ins, overhead, etc.) | | | 71.749 s | 18.9% |  |
Totals | | | 379.545 s | 100% | |
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 243 |
Non-code lines (comments, blank lines) | 96 |
Code lines (lines that can run) | 147 |
Code lines that did run | 32 |
Code lines that did not run | 115 |
Coverage (did run/can run) | 21.77 % |
Function listing
time calls line
1 function vi = interp3(varargin)
2 %INTERP3 3-D interpolation (table lookup).
3 % VI = INTERP3(X,Y,Z,V,XI,YI,ZI) interpolates to find VI, the values
4 % of the underlying 3-D function V at the points in arrays XI,YI
5 % and ZI. XI,YI,ZI must be arrays of the same size or vectors.
6 % Vector arguments that are not the same size, and have mixed
7 % orientations (i.e. with both row and column vectors) are passed
8 % through MESHGRID to create the Y1,Y2,Y3 arrays. Arrays X,Y and Z
9 % specify the points at which the data V is given.
10 %
11 % VI = INTERP3(V,XI,YI,ZI) assumes X=1:N, Y=1:M, Z=1:P
12 % where [M,N,P]=SIZE(V).
13 % VI = INTERP3(V,NTIMES) expands V by interleaving interpolates
14 % between every element, working recursively for NTIMES.
15 % INTERP3(V) is the same as INTERP3(V,1).
16 %
17 % VI = INTERP3(...,METHOD) specifies alternate methods. The default
18 % is linear interpolation. Available methods are:
19 %
20 % 'nearest' - nearest neighbor interpolation
21 % 'linear' - linear interpolation
22 % 'spline' - spline interpolation
23 % 'cubic' - cubic interpolation as long as the data is uniformly
24 % spaced, otherwise the same as 'spline'
25 %
26 % VI = INTERP3(...,METHOD,EXTRAPVAL) specifies a method and a value for
27 % VI outside of the domain created by X,Y and Z. Thus, VI will equal
28 % EXTRAPVAL for any value of XI,YI or ZI that is not spanned by X,Y and Z
29 % respectively. A method must be specified for EXTRAPVAL to be used, the
30 % default method is 'linear'.
31 %
32 % All the interpolation methods require that X,Y and Z be monotonic and
33 % plaid (as if they were created using MESHGRID). X,Y, and Z can be
34 % non-uniformly spaced.
35 %
36 % For example, to generate a course approximation of FLOW and
37 % interpolate over a finer mesh:
38 % [x,y,z,v] = flow(10);
39 % [xi,yi,zi] = meshgrid(.1:.25:10,-3:.25:3,-3:.25:3);
40 % vi = interp3(x,y,z,v,xi,yi,zi); % vi is 25-by-40-by-25
41 % slice(xi,yi,zi,vi,[6 9.5],2,[-2 .2]), shading flat
42 %
43 % See also INTERP1, INTERP2, INTERPN, MESHGRID.
44
45 % Copyright 1984-2011 The MathWorks, Inc.
46 % $Revision: 5.34.4.14 $ $Date: 2011/05/17 02:32:28 $
47
417 48 error(nargchk(1,9,nargin,'struct')); % allowing for an ExtrapVal
49
417 50 bypass = 0;
0.02 417 51 uniform = 1;
0.02 417 52 if (nargin>1)
0.01 417 53 if ischar(varargin{end}),
54 narg = nargin-1;
55 method = [varargin{end} ' ']; % Protect against short string.
56 if strncmpi(method,'s',1) || strncmpi(method, '*s', 2)
57 ExtrapVal = 'extrap'; % Splines can extrapolate
58 else
59 ExtrapVal = nan; % default ExtrapVal
60 end
61 index = 1;
0.01 417 62 elseif ( ischar(varargin{end-1}) && isnumeric(varargin{end}) )
417 63 narg = nargin-2;
417 64 method = [varargin{end-1} ' '];
417 65 ExtrapVal = varargin{end};
417 66 index = 2;
67 else
68 narg = nargin;
69 method = 'linear';
70 ExtrapVal = nan; % protecting default
71 end
0.01 417 72 if method(1)=='*', % Direct call bypass.
73 if method(2)=='l' % linear interpolation.
74 vi = linear(varargin{1:end-index},ExtrapVal);
75 return
76
77 elseif method(2)=='c' % cubic interpolation
78 vi = cubic(varargin{1:end-index},ExtrapVal);
79 return
80
81 elseif method(2)=='n', % Nearest neighbor interpolation
82 vi = nearest(varargin{1:end-index},ExtrapVal);
83 return
84
85 elseif method(2)=='s', % Spline
86 method = 'spline'; bypass = 1;
87
88 else
89 error(message('MATLAB:interp3:InvalidMethod', deblank( method )));
90
91 end
417 92 elseif method(1)=='s', % Spline interpolation
93 method = 'spline'; bypass = 1;
94 end
95 else
96 narg = nargin;
97 method = 'linear';
98 ExtrapVal = nan; % protecting default
99 end
100
417 101 if narg==1, % interp3(v), % Expand V
102 [nrows,ncols,npages] = size(varargin{1});
103 xi = 1:.5:ncols; yi = (1:.5:nrows)'; zi = (1:.5:npages);
104 x = 1:ncols; y = 1:nrows; z = 1:npages;
105 [msg,x,y,z,v,xi,yi,zi] = xyzvchk(x,y,z,varargin{1},xi,yi,zi);
106
417 107 elseif narg==2. % interp3(v,n), Expand V n times
108 [nrows,ncols,npages] = size(varargin{1});
109 ntimes = floor(varargin{2}(1));
110 xi = 1:1/(2^ntimes):ncols; yi = (1:1/(2^ntimes):nrows)';
111 zi = 1:1/(2^ntimes):npages;
112 x = 1:ncols; y = (1:nrows); z = 1:npages;
113 [msg,x,y,z,v,xi,yi,zi] = xyzvchk(x,y,z,varargin{1},xi,yi,zi);
114
417 115 elseif narg==4, % interp3(v,xi,yi,zi)
0.01 417 116 [nrows,ncols,npages] = size(varargin{1});
0.01 417 117 x = 1:ncols; y = (1:nrows); z = 1:npages;
101.15 417 118 [msg,x,y,z,v,xi,yi,zi] = xyzvchk(x,y,z,varargin{1:4});
119
120 elseif narg==3 || narg==5 || narg==6,
121 error(message('MATLAB:interp3:nargin'));
122
123 elseif narg==7, % interp3(x,y,z,v,xi,yi,zi)
124 [msg,x,y,z,v,xi,yi,zi] = xyzvchk(varargin{1:7});
125
126 end
127
0.01 417 128 if ~isempty(msg)
129 error(message(msg.identifier));
130 end
131
132 %
133 % Check for plaid data.
134 %
0.03 417 135 xx = x(1,:,1); yy = y(:,1,1); zz = z(1,1,:);
164.87 417 136 if (size(x,2)>1 && ~isequal(repmat(xx, [size(x,1) 1 size(x,3)]),x)) || ...
137 (size(y,1)>1 && ~isequal(repmat(yy, [1 size(y,2) size(y,3)]),y)) || ...
138 (size(z,3)>1 && ~isequal(repmat(zz, [size(z,1) size(z,2) 1]),z)),
139 error(message('MATLAB:interp3:meshgrid'));
140 end
141
142
143 %
144 % Check for non-equally spaced data. If so, map (x,y) and
145 % (xi,yi) to matrix (row,col) coordinate system.
146 %
417 147 if ~bypass,
0.13 417 148 xx = x(1,:,1).'; yy = y(:,1,1); zz = squeeze(z(1,1,:)); % columns
0.01 417 149 dx = diff(xx); dy = diff(yy); dz = diff(zz);
417 150 xdiff = max(abs(diff(dx))); if isempty(xdiff), xdiff = 0; end
0.01 417 151 ydiff = max(abs(diff(dy))); if isempty(ydiff), ydiff = 0; end
0.01 417 152 zdiff = max(abs(diff(dz))); if isempty(zdiff), zdiff = 0; end
0.01 417 153 if (xdiff > eps*max(xx)) || (ydiff > eps*max(yy)) || (zdiff > eps*max(zz))
154 if any(dx < 0), % Flip orientation of data so x is increasing.
155 x = flipdim(x,2); y = flipdim(y,2);
156 z = flipdim(z,2); v = flipdim(v,2);
157 xx = flipud(xx); dx = -flipud(dx);
158 end
159 if any(dy < 0), % Flip orientation of data so y is increasing.
160 x = flipdim(x,1); y = flipdim(y,1);
161 z = flipdim(z,1); v = flipdim(v,1);
162 yy = flipud(yy); dy = -flipud(dy);
163 end
164 if any(dz < 0), % Flip orientation of data so y is increasing.
165 x = flipdim(x,3); y = flipdim(y,3);
166 z = flipdim(z,3); v = flipdim(v,3);
167 zz = flipud(zz); dz = -flipud(dz);
168 end
169
170 if any(dx<=0) || any(dy<=0) || any(dz<=0),
171 error(message('MATLAB:interp3:XYorZNotMonotonic'));
172 end
173
174 % Bypass mapping code for cubic
175 if method(1)~='c',
176 % Determine the nearest location of xi in x
177 [xxi,j] = sort(xi(:));
178 [~,i] = sort([xx;xxi]);
179 si(i) = (1:length(i));
180 si = (si(length(xx)+1:end)-(1:length(xxi)))';
181 si(j) = si;
182
183 % Map values in xi to index offset (si) via linear interpolation
184 si(si<1) = 1;
185 si(si>length(xx)-1) = length(xx)-1;
186 si = si + (xi(:)-xx(si))./(xx(si+1)-xx(si));
187
188 % Determine the nearest location of yi in y
189 [yyi,j] = sort(yi(:));
190 [~,i] = sort([yy;yyi]);
191 ti(i) = (1:length(i));
192 ti = (ti(length(yy)+1:end)-(1:length(yyi)))';
193 ti(j) = ti;
194
195 % Map values in yi to index offset (ti) via linear interpolation
196 ti(ti<1) = 1;
197 ti(ti>length(yy)-1) = length(yy)-1;
198 ti = ti + (yi(:)-yy(ti))./(yy(ti+1)-yy(ti));
199
200 % Determine the nearest location of zi in z
201 [zzi,j] = sort(zi(:));
202 [~,i] = sort([zz;zzi]);
203 wi(i) = (1:length(i));
204 wi = (wi(length(zz)+1:end)-(1:length(zzi)))';
205 wi(j) = wi;
206
207 % Map values in zi to index offset (wi) via linear interpolation
208 wi(wi<1) = 1;
209 wi(wi>length(zz)-1) = length(zz)-1;
210 wi = wi + (zi(:)-zz(wi))./(zz(wi+1)-zz(wi));
211
212 [x,y,z] = meshgrid(ones(class(x)):size(x,2),...
213 ones(superiorfloat(y,z)):size(y,1),1:size(z,3));
214 xi(:) = si; yi(:) = ti; zi(:) = wi;
215 else
216 uniform = 0;
217 end
218 end
417 219 end
220
221 % Now do the interpolation based on method.
417 222 method = [lower(method),' ']; % Protect against short string
223
0.01 417 224 if method(1)=='l', % linear interpolation.
101.15 417 225 vi = linear(x,y,z,v,xi,yi,zi,ExtrapVal);
226
227 elseif method(1)=='c', % cubic interpolation
228 if uniform
229 vi = cubic(x,y,z,v,xi,yi,zi,ExtrapVal);
230 else
231 vi = spline3(x,y,z,v,xi,yi,zi,ExtrapVal);
232 end
233
234 elseif method(1)=='n', % Nearest neighbor interpolation
235 vi = nearest(x,y,z,v,xi,yi,zi,ExtrapVal);
236
237 elseif method(1)=='s', % Spline interpolation
238 vi = spline3(x,y,z,v,xi,yi,zi,ExtrapVal);
239
240 else
241 error(message('MATLAB:interp3:InvalidMethod', deblank( method )));
242
243 end
Other subfunctions in this file are not included in this listing.