| 1 |
enderton |
1.1 |
function zi = griddata_fast(delau,z,method) |
| 2 |
|
|
%GRIDDATA_FAST Data gridding and surface fitting. |
| 3 |
|
|
% ZI = GRIDDATA_FAST(DEL,Z) |
| 4 |
|
|
% |
| 5 |
|
|
% See also GRIDDATA_PREPROCESS |
| 6 |
|
|
|
| 7 |
|
|
% Based on |
| 8 |
|
|
% Clay M. Thompson 8-21-95 |
| 9 |
|
|
% Copyright 1984-2001 The MathWorks, Inc. |
| 10 |
|
|
% $Revision: 1.1 $ $Date: 2004/06/04 15:50:52 $ |
| 11 |
|
|
|
| 12 |
|
|
error(nargchk(2,3,nargin)) |
| 13 |
|
|
|
| 14 |
|
|
if nargin<3, method = 'linear'; end |
| 15 |
|
|
if ~isstr(method), |
| 16 |
|
|
error('METHOD must be one of ''linear'',''cubic'',''nearest'', or ''v4''.'); |
| 17 |
|
|
end |
| 18 |
|
|
|
| 19 |
|
|
|
| 20 |
|
|
% Sort x and y so duplicate points can be averaged before passing to delaunay |
| 21 |
|
|
|
| 22 |
|
|
switch lower(method), |
| 23 |
|
|
case 'linear' |
| 24 |
|
|
zi = linear(delau,z); |
| 25 |
|
|
% case 'cubic' |
| 26 |
|
|
% zi = cubic(x,y,z,xi,yi); |
| 27 |
|
|
% case 'nearest' |
| 28 |
|
|
% zi = nearest(x,y,z,xi,yi); |
| 29 |
|
|
% case {'invdist','v4'} |
| 30 |
|
|
% zi = gdatav4(x,y,z,xi,yi); |
| 31 |
|
|
otherwise |
| 32 |
|
|
error('Unknown method.'); |
| 33 |
|
|
end |
| 34 |
|
|
|
| 35 |
|
|
if nargout<=1, xi = zi; end |
| 36 |
|
|
|
| 37 |
|
|
|
| 38 |
|
|
%------------------------------------------------------------ |
| 39 |
|
|
function zi = linear(del,z) |
| 40 |
|
|
%LINEAR Triangle-based linear interpolation |
| 41 |
|
|
|
| 42 |
|
|
% Reference: David F. Watson, "Contouring: A guide |
| 43 |
|
|
% to the analysis and display of spacial data", Pergamon, 1994. |
| 44 |
|
|
|
| 45 |
|
|
z = z(:).'; % Treat z as a row so that code below involving |
| 46 |
|
|
% z(tri) works even when tri is 1-by-3. |
| 47 |
|
|
zi = sum(z(del.tri) .* del.w,2); |
| 48 |
|
|
|
| 49 |
|
|
zi = reshape(zi,del.siz); |
| 50 |
|
|
|
| 51 |
|
|
if ~isempty(del.out), zi(del.out) = NaN; end |
| 52 |
|
|
|
| 53 |
|
|
%------------------------------------------------------------ |