Mercurial > octave-nkf
comparison scripts/general/interp2.m @ 10635:d1978e7364ad
Print name of function in error() string messages.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 16 May 2010 22:26:54 -0700 |
parents | 95c3e38098bf |
children | 6e7590d003dc |
comparison
equal
deleted
inserted
replaced
10634:60542efcfa2c | 10635:d1978e7364ad |
---|---|
129 print_usage (); | 129 print_usage (); |
130 endswitch | 130 endswitch |
131 | 131 |
132 ## Type checking. | 132 ## Type checking. |
133 if (!ismatrix (Z)) | 133 if (!ismatrix (Z)) |
134 error ("interp2 expected matrix Z"); | 134 error ("interp2: expected matrix Z"); |
135 endif | 135 endif |
136 if (!isempty (n) && !isscalar (n)) | 136 if (!isempty (n) && !isscalar (n)) |
137 error ("interp2 expected scalar n"); | 137 error ("interp2: expected scalar n"); |
138 endif | 138 endif |
139 if (!ischar (method)) | 139 if (!ischar (method)) |
140 error ("interp2 expected string 'method'"); | 140 error ("interp2: expected string 'method'"); |
141 endif | 141 endif |
142 if (ischar (extrapval) || strcmp (extrapval, "extrap")) | 142 if (ischar (extrapval) || strcmp (extrapval, "extrap")) |
143 extrapval = []; | 143 extrapval = []; |
144 elseif (!isscalar (extrapval)) | 144 elseif (!isscalar (extrapval)) |
145 error ("interp2 expected n extrapval"); | 145 error ("interp2: expected n extrapval"); |
146 endif | 146 endif |
147 | 147 |
148 ## Define X, Y, XI, YI if needed | 148 ## Define X, Y, XI, YI if needed |
149 [zr, zc] = size (Z); | 149 [zr, zc] = size (Z); |
150 if (isempty (X)) | 150 if (isempty (X)) |
151 X = 1:zc; | 151 X = 1:zc; |
152 Y = 1:zr; | 152 Y = 1:zr; |
153 endif | 153 endif |
154 if (! isnumeric (X) || ! isnumeric (Y)) | 154 if (! isnumeric (X) || ! isnumeric (Y)) |
155 error ("interp2 expected numeric X, Y"); | 155 error ("interp2: expected numeric X, Y"); |
156 endif | 156 endif |
157 if (! isempty (n)) | 157 if (! isempty (n)) |
158 p = 2^n; | 158 p = 2^n; |
159 XI = (p:p*zc)/p; | 159 XI = (p:p*zc)/p; |
160 YI = (p:p*zr)'/p; | 160 YI = (p:p*zr)'/p; |
161 endif | 161 endif |
162 if (! isnumeric (XI) || ! isnumeric (YI)) | 162 if (! isnumeric (XI) || ! isnumeric (YI)) |
163 error ("interp2 expected numeric XI, YI"); | 163 error ("interp2: expected numeric XI, YI"); |
164 endif | 164 endif |
165 | 165 |
166 | 166 |
167 if (strcmp (method, "linear") || strcmp (method, "nearest") ... | 167 if (strcmp (method, "linear") || strcmp (method, "nearest") ... |
168 || strcmp (method, "pchip")) | 168 || strcmp (method, "pchip")) |
171 if (isvector (X) && isvector (Y)) | 171 if (isvector (X) && isvector (Y)) |
172 X = X(:); Y = Y(:); | 172 X = X(:); Y = Y(:); |
173 elseif (size_equal (X, Y)) | 173 elseif (size_equal (X, Y)) |
174 X = X(1,:)'; Y = Y(:,1); | 174 X = X(1,:)'; Y = Y(:,1); |
175 else | 175 else |
176 error ("X and Y must be matrices of same size"); | 176 error ("interp2: X and Y must be matrices of same size"); |
177 endif | 177 endif |
178 if (columns (Z) != length (X) || rows (Z) != length (Y)) | 178 if (columns (Z) != length (X) || rows (Z) != length (Y)) |
179 error ("X and Y size must match Z dimensions"); | 179 error ("interp2: X and Y size must match Z dimensions"); |
180 endif | 180 endif |
181 | 181 |
182 ## If Xi and Yi are vectors of different orientation build a grid | 182 ## If Xi and Yi are vectors of different orientation build a grid |
183 if ((rows (XI) == 1 && columns (YI) == 1) | 183 if ((rows (XI) == 1 && columns (YI) == 1) |
184 || (columns (XI) == 1 && rows (YI) == 1)) | 184 || (columns (XI) == 1 && rows (YI) == 1)) |
185 [XI, YI] = meshgrid (XI, YI); | 185 [XI, YI] = meshgrid (XI, YI); |
186 elseif (! size_equal (XI, YI)) | 186 elseif (! size_equal (XI, YI)) |
187 error ("XI and YI must be matrices of same size"); | 187 error ("interp2: XI and YI must be matrices of same size"); |
188 endif | 188 endif |
189 | 189 |
190 ## if XI, YI are vectors, X and Y should share their orientation. | 190 ## if XI, YI are vectors, X and Y should share their orientation. |
191 if (rows (XI) == 1) | 191 if (rows (XI) == 1) |
192 if (rows (X) != 1) | 192 if (rows (X) != 1) |
321 ## If X and Y vectors produce a grid from them | 321 ## If X and Y vectors produce a grid from them |
322 if (isvector (X) && isvector (Y)) | 322 if (isvector (X) && isvector (Y)) |
323 X = X(:).'; | 323 X = X(:).'; |
324 Y = Y(:); | 324 Y = Y(:); |
325 if (!isequal ([length(X), length(Y)], size(Z))) | 325 if (!isequal ([length(X), length(Y)], size(Z))) |
326 error ("X and Y size must match Z dimensions"); | 326 error ("interp2: X and Y size must match Z dimensions"); |
327 endif | 327 endif |
328 elseif (!size_equal (X, Y)) | 328 elseif (!size_equal (X, Y)) |
329 error ("X and Y must be matrices of same size"); | 329 error ("interp2: X and Y must be matrices of same size"); |
330 if (! size_equal (X, Z)) | 330 if (! size_equal (X, Z)) |
331 error ("X and Y size must match Z dimensions"); | 331 error ("interp2: X and Y size must match Z dimensions"); |
332 endif | 332 endif |
333 endif | 333 endif |
334 | 334 |
335 ## If Xi and Yi are vectors of different orientation build a grid | 335 ## If Xi and Yi are vectors of different orientation build a grid |
336 if ((rows (XI) == 1 && columns (YI) == 1) | 336 if ((rows (XI) == 1 && columns (YI) == 1) |
337 || (columns (XI) == 1 && rows (YI) == 1)) | 337 || (columns (XI) == 1 && rows (YI) == 1)) |
338 ## Do nothing | 338 ## Do nothing |
339 elseif (! size_equal (XI, YI)) | 339 elseif (! size_equal (XI, YI)) |
340 error ("XI and YI must be matrices of same size"); | 340 error ("interp2: XI and YI must be matrices of same size"); |
341 endif | 341 endif |
342 | 342 |
343 ## FIXME bicubic/__splinen__ don't handle arbitrary XI, YI | 343 ## FIXME bicubic/__splinen__ don't handle arbitrary XI, YI |
344 if (strcmp (method, "cubic")) | 344 if (strcmp (method, "cubic")) |
345 if (isgriddata (XI) && isgriddata (YI')) | 345 if (isgriddata (XI) && isgriddata (YI')) |
399 "spline"); | 399 "spline"); |
400 else | 400 else |
401 error ("interp2: input data must have `meshgrid' format"); | 401 error ("interp2: input data must have `meshgrid' format"); |
402 endif | 402 endif |
403 else | 403 else |
404 error ("interpolation method not recognized"); | 404 error ("interp2: interpolation method not recognized"); |
405 endif | 405 endif |
406 | 406 |
407 endif | 407 endif |
408 endfunction | 408 endfunction |
409 | 409 |