IDWInterpolant

PURPOSE ^

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 classdef IDWInterpolant < Interpolant
0002     %DelaunayInterpolant Summary of this class goes here
0003     %   Detailed explanation goes here
0004     
0005     properties
0006         searchObj;        
0007         power;
0008     end
0009     
0010     methods
0011         function obj = IDWInterpolant(x, y, z, varargin)            
0012             %IDWInterpolant Construct an instance of this class
0013             %   Detailed explanation goes here
0014             
0015             % Superclass constructor
0016             obj@Interpolant(x, y, z);
0017             
0018             % Validation functions for the input parameters
0019             validGreaterThanZero = @(x) isscalar(x) && x > 0;
0020             validSearchType = @(x) ischar(x) && strcmpi(x, 'radial') || strcmpi(x, 'knn');
0021             validDistanceType = @(x) ischar(x) && strcmpi(x, 'euclidean') || strcmpi(x, 'haversine');
0022             
0023             % Check the input parameters using inputParser
0024             p = inputParser;
0025             addParameter(p, 'Radius', 5, validGreaterThanZero);    
0026             addParameter(p, 'SearchType', 'radial', validSearchType);
0027             addParameter(p, 'K', 25, validGreaterThanZero);
0028             addParameter(p, 'Power', 2, validGreaterThanZero);
0029             addParameter(p, 'DistanceType', 'euclidean', validDistanceType);
0030             parse(p, varargin{:});
0031             
0032             % Retrieve the members from the inputParser
0033             obj.power = p.Results.Power;            
0034             obj.searchObj = QueryNeighborhood(obj.data, 'Radius', p.Results.Radius, ...
0035                                                         'SearchType', p.Results.SearchType, ...
0036                                                         'K', p.Results.K, ...
0037                                                         'DistanceType', p.Results.DistanceType);
0038         end
0039         
0040         function z = interpolate(obj, x, y)            
0041             Interpolant.checkSizes(x, y);            
0042             
0043             [ind, distances] = obj.searchObj.getNeighbors(x, y);
0044             
0045             z = zeros(size(x));
0046             for i = 1:numel(ind)
0047                 zi = obj.data(ind{i}, 3)';
0048                 d = distances{i};
0049                 if min(d) < 0.0001
0050                    z(i) = zi(1); % The one with minimum distance is the first, according to rangesearch/knnsearch documentation
0051                    continue;
0052                 end                
0053                 dw = d.^obj.power;
0054                 diw = 1./dw;
0055                 z(i) = sum(diw.*zi)/sum(diw);
0056             end
0057         end        
0058     end
0059 end
0060

Generated on Thu 10-Dec-2020 17:34:27 by m2html © 2005