View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Inverse Distance Weighted (IDW) or Simple Moving Average (SMA) INTERPOLATION

4.8 | 5 ratings Rate this file 12 Downloads (last 30 days) File Size: 2.79 KB File ID: #27562 Version: 1.0

Inverse Distance Weighted (IDW) or Simple Moving Average (SMA) INTERPOLATION



This function computes at (Xi,Yi) unknown locations the IDW (w<0) or the SMA (w=0) predictions.

| Watch this File

File Information

This function computes at (Xi,Yi) unknown locations the IDW (w<0) or the SMA (w=0) predictions using r1 neighbourhood type ('n':number of points; 'r':radius) and r2 neighbourhood size from Vc measured values at (Xc,Yc) locations.

% Vi: (mandatory) [PxQ] gIDW interpolated values
% --> P=1, Q=1 yields interpolation at one
% point
% --> P>1, Q=1 yields interpolation at a
% vector of points
% --> P>1, Q>1 yields interpolation at a
% (ir)regular grid of points

% Xc: (mandatory) [Nx1] x coordinates of known points
% Yc: (mandatory) [Nx1] y coordinates of known points
% Vc: (mandatory) [Nx1] known values at [Xc, Yc] locations
% Xi: (mandatory) [PxQ] x coordinates of points to be interpolated
% Yi: (mandatory) [PxQ] y coordinates of points to be interpolated
% w: (mandatory) [scalar] distance weight
% --> w<0, for Inverse Distance Weighted
% interpolation [IDW]
% --> w=0, for Simple Moving Average (only
% if neighorhood size is local and not
% global) [SMA]
% r1: (optional) [string] neighbourhood type
% --> 'n' (default) number of neighbours
% --> 'r' fixed radius length
% r2: (optional) [scalar] neighbourhood size
% --> number of neighbours, if r1=='n'
% default is length(Xc)
% --> radius length, if r1=='r'
% default is largest distance between known points

% --- IDW ---
% all inputs:
% Vi = gIDW(Xc,Yc,Vc,Xi,Yi,-2,'n',30);
% 6 inputs:
% Vi = gIDW(Xc,Yc,Vc,Xi,Yi,-2);
% --> r1='n'; r2=length(Xc);
% 7 inputs:
% Vi = gIDW(Xc,Yc,Vc,Xi,Yi,-2,'n');
% --> r2=length(Xc);
% Vi = gIDW(Xc,Yc,Vc,Xi,Yi,-2,'r');
% --> r2=largest distance between know points [Xi,Yi] (see D1 calculation)
% --- SMA ---
% Vi = gIDW(Xc,Yc,Vc,Xi,Yi,0,'n',10);
% --- Spatial Map ---
% Vi = gIDW(Xc,Yc,Vc,Xi,Yi,-2,'n',10);
% -with Xi and Yi 2D arrays of coordinates relative to an (ir)regular
% grid.

% Interpolation at one point location:
% Vi = gIDW([1:1:10]',[2:2:20]',rand(10,1)*100,5.5,11,-2,'n');
% ---
% Interpolation at a regular grid of unknown points:
% XYc = [1:1:10]';
% Vc = rand(10,1)*100;
% Xi = rand(50,50)*10;
% Yi = rand(50,50)*10;
% [Xi,Yi] = meshgrid(XYc);
% Vi = gIDW(XYc,XYc,Vc,Xi,Yi,-2,'r',3);
% hold on
% mapshow(Xi,Yi,Vi,'DisplayType','surface')
% colormap gray
% scatter(XYc,XYc,Vc,'filled','MarkerFaceColor','g','MarkerEdgeColor','y')
% axis([0,11,0,11])
% hold off


Inverse Distance Weight inspired this file.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (6)
01 Jan 2017 Cynthia Gerlein-Safdi

This is a great, easy to use function that gives great results. It's a bit slow if your matrix gets big, but I think that will be true of any good interpolation.
One thing that would be useful is the possibility to calculate the confidence intervals, for example by jackknifing. If anyone knows of another code that could complement this one to explore standard error/confidence intervals, please let me know!!!

08 May 2016 fan bi

fan bi (view profile)

But it seems a bug when input Xi=Xc and Yi=Yc, the output Vi are not equal to Vc.

Line 123 to 124 should be:
Vcc = Vc(D<r2);
D = D(D<r2);
instead of
D = D(D<r2);
Vcc = Vc(D<r2);

20 Apr 2016 Giuliano Langella

@Muhammad Usman Saleem
Be careful that the proposed function itself DOES "extrapolate" according to the availability of "external" locations given in (Xi,Yi) as input.
You can also regulate the extension of extrapolation by configuring r1 and r2 parameters (using one of distance or minimum number of measured points).
Feel free to contact me if you require more information.

Comment only
20 Apr 2016 Muhammad Usman Saleem

this function, DO NOT extrapolate through IDW of missing data. Be careful to use please

20 Nov 2014 ouc

ouc (view profile)

18 Jul 2011 liu

liu (view profile)

Contact us