demoInterpolants

PURPOSE ^

demoInterpolants Script showing the different interpolants available in the toolbox.

SYNOPSIS ^

function demoInterpolants(dataId)

DESCRIPTION ^

demoInterpolants Script showing the different interpolants available in the toolbox.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function demoInterpolants(dataId)
0002 %demoInterpolants Script showing the different interpolants available in the toolbox.
0003 
0004     %% Parse parameters
0005     if nargin < 1 || isempty(dataId)
0006         dataId = 'seamount';
0007     end
0008     
0009     %% Get the sample data and options
0010     [x, y, z, xi, yi, zt, demoOptions] = getSampleDataset(dataId);
0011     
0012     %% Show the original function evaluated on the grid, if available
0013     figure;
0014     xLabel = demoOptions.Plot.XLabel;
0015     yLabel = demoOptions.Plot.YLabel;
0016     zLabel = demoOptions.Plot.ZLabel;
0017     axisEqual = demoOptions.Plot.AxisEqual;
0018     spNumRows = 3;
0019     spNumCols = 3;
0020     if ~isempty(zt)
0021         plotResult([], [], [], xi, yi, zt, spNumRows, spNumCols, 1, 'Original Function', xLabel, yLabel, zLabel, axisEqual);    
0022     else
0023         % Print a text in the subplot location?
0024     end
0025     
0026     %% Prepare show the scattered input data
0027     plotResult(x, y, z, [], [], [], spNumRows, spNumCols, 2, 'Input Samples', xLabel, yLabel, zLabel, axisEqual);
0028         
0029     %% Interpolate with each of the methods available
0030     
0031     %% Nearest neighbor
0032     fprintf('- Interpolating using the Nearest Neighbor Interpolant...');
0033     tic;
0034     nearNeighInterp = NearestNeighborInterpolant(x, y, z);
0035     ziNear = nearNeighInterp.interpolate(xi, yi);
0036     t = toc;
0037     fprintf(' done (%f seconds)\n', t);
0038     plotResult(x, y, z, xi, yi, ziNear, spNumRows, spNumCols, 3, 'Nearest Neighbor Interpolant', xLabel, yLabel, zLabel, axisEqual);
0039 
0040     %% Delaunay Triangulation
0041     fprintf('- Interpolating using the Delaunay Interpolant...');
0042     tic;    
0043     dtInterp = DelaunayTINInterpolant(x, y, z);
0044     ziDT = dtInterp.interpolate(xi, yi);
0045     t = toc;
0046     fprintf(' done (%f seconds)\n', t);
0047     plotResult(x, y, z, xi, yi, ziDT, spNumRows, spNumCols, 4, 'Delaunay (linear) Interpolant', xLabel, yLabel, zLabel, axisEqual);
0048 
0049     %% Natural Neighbors
0050     fprintf('- Interpolating using the Natural Neighbors Interpolant...');
0051     tic;
0052     naturNeighInterp = NaturalNeighborsInterpolant(x, y, z);
0053     ziNatur = naturNeighInterp.interpolate(xi, yi);
0054     t = toc;
0055     fprintf(' done (%f seconds)\n', t);
0056     plotResult(x, y, z, xi, yi, ziNatur, spNumRows, spNumCols, 5, 'Natural Neighbor Interpolant', xLabel, yLabel, zLabel, axisEqual);
0057 
0058     %% IDW interpolant
0059     fprintf('- Interpolating using the Inverse-Distance-Weighted Interpolant...');
0060     tic;
0061     idwInterp = IDWInterpolant(x, y, z, 'DistanceType', demoOptions.DistanceType, ...
0062                                         'SearchType', demoOptions.IDW.SearchType, ...
0063                                         'k', demoOptions.IDW.K, ...
0064                                         'Radius', demoOptions.IDW.Radius, ...
0065                                         'Power', demoOptions.IDW.Power);
0066     ziIDW = idwInterp.interpolate(xi, yi);
0067     t = toc;
0068     fprintf(' done (%f seconds)\n', t);
0069     plotResult(x, y, z, xi, yi, ziIDW, spNumRows, spNumCols, 6, 'Inverse Distance Weighted Interpolant', xLabel, yLabel, zLabel, axisEqual);
0070 
0071     %% RBF interpolant
0072     fprintf('- Interpolating using the Radial Basis Function Interpolant (%s kernel)...', demoOptions.RBF.RBF);
0073     tic;
0074     rbfInterp = RBFInterpolant(x, y, z, 'DistanceType', demoOptions.DistanceType, ...
0075                                         'PolynomialDegree', demoOptions.RBF.(demoOptions.RBF.RBF).PolynomialDegree, ...
0076                                         'RBF', demoOptions.RBF.RBF, ...
0077                                         'RBFEpsilon', demoOptions.RBF.(demoOptions.RBF.RBF).RBFEpsilon, ... 
0078                                         'Regularization', demoOptions.RBF.(demoOptions.RBF.RBF).Regularization);
0079     ziRBF = rbfInterp.interpolate(xi, yi);
0080     t = toc;
0081     fprintf(' done (%f seconds)\n', t);
0082     plotResult(x, y, z, xi, yi, ziRBF, spNumRows, spNumCols, 7, ['(' demoOptions.RBF.RBF ') RBF Interpolant'], xLabel, yLabel, zLabel, axisEqual);
0083 
0084     %% Kriging interpolant
0085     fprintf('- Interpolating using the Kriging Interpolant...');
0086     tic;
0087     % Create the experimental variogram from the samples
0088     vg = Variogram(x, y, z, 'model', demoOptions.Kriging.Variogram.Type, ...
0089                             'DistanceType', demoOptions.DistanceType, ...
0090                             'NumBins', demoOptions.Kriging.Variogram.NumSamples, ...
0091                             'OptimNugget', demoOptions.Kriging.Variogram.OptimNugget);
0092     
0093     % Use it in the Kriging
0094     krigInterp = KrigingInterpolant(x, y, z, vg, 'DistanceType', demoOptions.DistanceType, ...
0095                                                  'PolynomialDegree', demoOptions.Kriging.PolynomialDegree, ...
0096                                                  'Regularization', demoOptions.Kriging.Regularization);
0097     ziKrig = krigInterp.interpolate(xi, yi);
0098     t = toc;
0099     fprintf(' done (%f seconds)\n', t);
0100     plotResult(x, y, z, xi, yi, ziKrig, spNumRows, spNumCols, 8, 'Kriging Interpolant', xLabel, yLabel, zLabel, axisEqual);
0101 
0102     %% MLS interpolant
0103     fprintf('- Interpolating using the Moving Least Squares Interpolant (%s kernel)...', demoOptions.MLS.RBF);
0104     tic;
0105     rbfType = 'wendland';
0106     epsilon = 3; % That is, support in this case
0107     mlsInterp = MLSInterpolant(x, y, z, 'DistanceType', demoOptions.DistanceType, ...
0108                                         'PolynomialDegree', demoOptions.MLS.PolynomialDegree, ...
0109                                         'RBF', demoOptions.MLS.RBF, ...
0110                                         'RBFEpsilon', demoOptions.MLS.RBFEpsilon, ...
0111                                         'MinSamples', demoOptions.MLS.MinSamples);
0112     ziMLS = mlsInterp.interpolate(xi, yi);
0113     t = toc;
0114     fprintf(' done (%f seconds)\n', t);
0115     plotResult(x, y, z, xi, yi, ziMLS, spNumRows, spNumCols, 9, ['(' rbfType ') MLS Interpolant'], xLabel, yLabel, zLabel, axisEqual);
0116     
0117 end

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