Interpolation for 2-D gridded data in meshgrid format (2024)

Interpolation for 2-D gridded data in meshgrid format

collapse all in page

Syntax

Vq = interp2(X,Y,V,Xq,Yq)

Vq = interp2(V,Xq,Yq)

Vq = interp2(V)

Vq = interp2(V,k)

Vq = interp2(___,method)

Vq = interp2(___,method,extrapval)

Description

example

Vq = interp2(X,Y,V,Xq,Yq) returnsinterpolated values of a function of two variables at specific querypoints using linear interpolation. The results always pass throughthe original sampling of the function. X and Y containthe coordinates of the sample points. V containsthe corresponding function values at each sample point. Xq and Yq containthe coordinates of the query points.

Vq = interp2(V,Xq,Yq) assumes a default grid of sample points. The default grid points cover the rectangular region, X=1:n and Y=1:m, where [m,n] = size(V). Use this syntax when you want to conserve memory and are not concerned about the absolute distances between points.

Vq = interp2(V) returnsthe interpolated values on a refined grid formed by dividing the intervalbetween sample values once in each dimension.

example

Vq = interp2(V,k) returns the interpolated values on a refined grid formed by repeatedlyhalving the intervals k times in each dimension.This results in 2^k-1 interpolated points betweensample values.

example

Vq = interp2(___,method) specifies an alternative interpolation method: 'linear', 'nearest', 'cubic', 'makima', or 'spline'. The default method is 'linear'.

example

Vq = interp2(___,method,extrapval) alsospecifies extrapval, a scalar value that is assignedto all queries that lie outside the domain of the sample points.

If you omit the extrapval argument for queriesoutside the domain of the sample points, then based on the method argument interp2 returnsone of the following:

  • Extrapolated values for the 'spline' and 'makima' methods

  • NaN values for other interpolation methods

Examples

collapse all

Interpolate over a Grid Using Default Method

Open Live Script

Coarsely sample the peaks function.

[X,Y] = meshgrid(-3:3);V = peaks(X,Y);

Plot the coarse sampling.

figuresurf(X,Y,V)title('Original Sampling');

Interpolation for 2-D gridded data in meshgrid format (1)

Create the query grid with spacing of 0.25.

[Xq,Yq] = meshgrid(-3:0.25:3);

Interpolate at the query points.

Vq = interp2(X,Y,V,Xq,Yq);

Plot the result.

figuresurf(Xq,Yq,Vq);title('Linear Interpolation Using Finer Grid');

Interpolation for 2-D gridded data in meshgrid format (2)

Interpolate over a Grid Using Cubic Method

Open Live Script

Coarsely sample the peaks function.

Plot the coarse sampling.

figuresurf(X,Y,V)title('Original Sampling');

Interpolation for 2-D gridded data in meshgrid format (3)

Create the query grid with spacing of 0.25.

[Xq,Yq] = meshgrid(-3:0.25:3);

Interpolate at the query points, and specify cubic interpolation.

Vq = interp2(X,Y,V,Xq,Yq,'cubic');

Plot the result.

figuresurf(Xq,Yq,Vq);title('Cubic Interpolation Over Finer Grid');

Interpolation for 2-D gridded data in meshgrid format (4)

Refine Grayscale Image

Open Live Script

Load some image data into the workspace.

load flujet.matcolormap gray

Isolate a small region of the image and cast it to single-precision.

V = single(X(200:300,1:25));

Display the image region.

imagesc(V);axis offtitle('Original Image')

Interpolation for 2-D gridded data in meshgrid format (5)

Insert interpolated values by repeatedly dividing the intervals between points of the refined grid five times in each dimension.

Vq = interp2(V,5);

Display the result.

imagesc(Vq);axis offtitle('Linear Interpolation')

Interpolation for 2-D gridded data in meshgrid format (6)

Evaluate Outside the Domain of X and Y

Open Live Script

Coarsely sample a function over the range, [-2, 2] in both dimensions.

[X,Y] = meshgrid(-2:0.75:2);R = sqrt(X.^2 + Y.^2)+ eps;V = sin(R)./(R);

Plot the coarse sampling.

figuresurf(X,Y,V)xlim([-4 4])ylim([-4 4])title('Original Sampling')

Interpolation for 2-D gridded data in meshgrid format (7)

Create the query grid that extends beyond the domain of X and Y.

[Xq,Yq] = meshgrid(-3:0.2:3);

Perform cubic interpolation within the domain of X and Y, and assign all queries that fall outside to zero.

Vq = interp2(X,Y,V,Xq,Yq,'cubic',0);

Plot the result.

figuresurf(Xq,Yq,Vq)title('Cubic Interpolation with Vq=0 Outside Domain of X and Y');

Interpolation for 2-D gridded data in meshgrid format (8)

Input Arguments

collapse all

X,YSample grid points
matrices | vectors

Sample grid points, specified as real matrices or vectors. Thesample grid points must be unique.

  • If X and Y arematrices, then they contain the coordinates of a full grid (in meshgrid format).Use the meshgrid function tocreate the X and Y matricestogether. Both matrices must be the same size.

  • If X and Y are vectors, then they are treated as grid vectors. The values in both vectors must be strictly monotonic, either increasing or decreasing.

Example: [X,Y] = meshgrid(1:30,-10:10)

Data Types: single | double

VSample values
matrix

Sample values, specified as a real or complex matrix. The sizerequirements for V depend on the size of X and Y:

  • If X and Y arematrices representing a full grid (in meshgrid format),then V must be the same size as X and Y.

  • If X and Y aregrid vectors, then V must be a matrix containing length(Y) rowsand length(X) columns.

If V contains complex numbers, then interp2 interpolatesthe real and imaginary parts separately.

Example: rand(10,10)

Data Types: single | double
Complex Number Support: Yes

Xq,YqQuery points
scalars | vectors | matrices | arrays

Query points, specified as a real scalars, vectors, matrices,or arrays.

  • If Xq and Yq arescalars, then they are the coordinates of a single query point.

  • If Xq and Yq arevectors of different orientations, then Xq and Yq aretreated as grid vectors.

  • If Xq and Yq arevectors of the same size and orientation, then Xq and Yq aretreated as scatteredpoints in 2-D space.

  • If Xq and Yq arematrices, then they represent either a full grid of query points (in meshgrid format)or scattered points.

  • If Xq and Yq areN-D arrays, then they represent scattered points in 2-D space.

Example: [Xq,Yq] = meshgrid((1:0.1:10),(-5:0.1:0))

Data Types: single | double

kRefinement factor
1 (default) | real, nonnegative, integer scalar

Refinement factor, specified as a real, nonnegative, integerscalar. This value specifies the number of times to repeatedly dividethe intervals of the refined grid in each dimension. This resultsin 2^k-1 interpolated points between sample values.

If k is 0, then Vq isthe same as V.

interp2(V,1) is the same as interp2(V).

The following illustration shows the placement of interpolatedvalues (in red) among nine sample values (in black) for k=2.

Interpolation for 2-D gridded data in meshgrid format (9)

Example: interp2(V,2)

Data Types: single | double

methodInterpolation method
'linear' (default) | 'nearest' | 'cubic' | 'spline' | 'makima'

Interpolation method, specified as one of the options in this table.

MethodDescriptionContinuityComments
'linear'The interpolated value at a query point is based on linear interpolation of the values at neighboring grid points in each respective dimension. This is the default interpolation method.C0
  • Requires at least two grid points in each dimension

  • Requires more memory than 'nearest'

'nearest'The interpolated value at a query point is the value at the nearest sample grid point. Discontinuous
  • Requires two grid points in each dimension.

  • Fastest computation with modest memory requirements

'cubic'The interpolated value at a query point is based on a cubic interpolation of the values at neighboring grid points in each respective dimension. The interpolation is based on a cubic convolution.C1
  • Grid must have uniform spacing in each dimension, but the spacing does not have to be the same for all dimensions

  • Requires at least four points in each dimension

  • Requires more memory and computation time than 'linear'

'makima'Modified Akima cubic Hermite interpolation. The interpolated value at a query point is based on a piecewise function of polynomials with degree at most three evaluated using the values of neighboring grid points in each respective dimension. The Akima formula is modified to avoid overshoots.C1
  • Requires at least 2 points in each dimension

  • Produces fewer undulations than 'spline'

  • Computation time is typically less than 'spline', but the memory requirements are similar

'spline'The interpolated value at a query point is based on a cubic interpolation of the values at neighboring grid points in each respective dimension. The interpolation is based on a cubic spline using not-a-knot end conditions.C2
  • Requires four points in each dimension

  • Requires more memory and computation time than 'cubic'

extrapvalFunction value outside domain of X and Y
scalar

Function value outside domain of X and Y,specified as a real or complex scalar. interp2 returnsthis constant value for all points outside the domain of X and Y.

Example: 5

Example: 5+1i

Data Types: single | double
Complex Number Support: Yes

Output Arguments

collapse all

Vq — Interpolated values
scalar | vector | matrix

Interpolated values, returned as a real or complex scalar, vector,or matrix. The size and shape of Vq depends onthe syntax you use and, in some cases, the size and value of the inputarguments.

SyntaxesSpecialConditionsSize of VqExample
interp2(X,Y,V,Xq,Yq)
interp2(V,Xq,Yq)
and variations of these syntaxes that include method or extrapval
Xq, Yq are scalarsScalarsize(Vq) = [1 1] when you pass Xq and Yq asscalars.
Same as aboveXq, Yq are vectors ofthe same size and orientationVector of same size and orientation as Xq and YqIf size(Xq) = [100 1]
and size(Yq)= [100 1],
then size(Vq) = [1001].
Same as aboveXq, Yq are vectors ofmixed orientationMatrix in which the number of rows is length(Yq),and the number of columns is length(Xq)If size(Xq) = [1 100]
and size(Yq)= [50 1],
then size(Vq) = [50 100].
Same as aboveXq, Yq are matrices orarrays of the same sizeMatrix or array of the same size as Xq and YqIf size(Xq) = [50 25]
and size(Yq)= [50 25],
then size(Vq) = [5025].
interp2(V,k)
and variationsof this syntax that include method or extrapval
None

Matrix in which the number of rows is:
2^k* (size(V,1)-1)+1,

and thenumber of columns is:
2^k * (size(V,2)-1)+1

If size(V) = [10 20]
and k= 2,
then size(Vq) = [37 77].

More About

collapse all

Strictly Monotonic

A set of values that are always increasingor decreasing, without reversals. For example, the sequence, a= [2 4 6 8] is strictly monotonic and increasing. The sequence, b= [2 4 4 6 8] is not strictly monotonic because there isno change in value between b(2) and b(3).The sequence, c = [2 4 6 8 6] contains a reversalbetween c(4) and c(5), so itis not monotonic at all.

Full Grid (in meshgrid Format)

For interp2, the fullgrid is a pair of matrices whose elements represent a grid of pointsover a rectangular region. One matrix contains the x-coordinates,and the other matrix contains the y-coordinates.The values in the x-matrix are strictly monotonic and increasingalong the rows. The values along its columns are constant. The valuesin the y-matrix are strictly monotonic and increasingalong the columns. The values along its rows are constant. Use the meshgrid function to create a full gridthat you can pass to interp2.

For example, the following code creates a full grid for theregion, –1 ≤ x ≤ 3 and 1 ≤ y ≤4:

[X,Y] = meshgrid(-1:3,(1:4))
X = -1 0 1 2 3 -1 0 1 2 3 -1 0 1 2 3 -1 0 1 2 3Y = 1 1 1 1 1 2 2 2 2 2 3 3 3 3 3 4 4 4 4 4

Grid vectors are a more compact format to represent a grid than the full grid. The relation between the two formats and the matrix of sample values V is

Interpolation for 2-D gridded data in meshgrid format (10)

Grid Vectors

For interp2, grid vectors consist of a pair of vectors that define the x- and y-coordinates in a grid. The row vector defines x-coordinates, and the column vector defines y-coordinates.

Interpolation for 2-D gridded data in meshgrid format (11)

For example, the following code creates the grid vectors that specify the region, –1 ≤ x ≤ 3 and 1 ≤ y ≤ 4:

x = -1:3;y = (1:4)';

Scattered Points

For interp2, scatteredpoints consist of a pair of arrays that define a collection of pointsscattered in 2-D space. One array contains the x-coordinates,and the other contains the y-coordinates.

For example, the following code specifies the points, (2,7),(5,3), (4,1), and (10,9):

x = [2 5; 4 10];y = [7 3; 1 9];

Extended Capabilities

Version History

Introduced before R2006a

See Also

griddata | interp1 | interp3 | interpn | meshgrid | griddedInterpolant | scatteredInterpolant

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Interpolation for 2-D gridded data in meshgrid format (12)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Interpolation for 2-D gridded data in meshgrid format (2024)

FAQs

How do you interpolate between two data sets? ›

How to interpolate
  1. Identify your data. Use a table to list your data. ...
  2. Create a line of best fit. After using the values to plot a graph, you can draw a line of best fit. ...
  3. Determine your value for interpolation. ...
  4. Use the linear interpolation equation. ...
  5. Solve the equation.
Sep 30, 2022

What is a 2d interpolation? ›

Two dimensional interpolation takes a series of (x,y,z) points and generates estimated values for z's at new (x,y) points. Interpolation is used when the function that generated the original (x,y,z) points is unknown. Interpolation is related to, but distinct from, fitting a function to a series of points.

What is the difference between griddedInterpolant and interp2? ›

There are memory and performance benefits to using griddedInterpolant objects over the interp functions. griddedInterpolant offers substantial performance improvements for repeated queries of the interpolant object, whereas the interp functions perform a new calculation each time they are called.

Which MATLAB function will be useful for interpolating a gridded data on some 3D surface? ›

Vq = interp3( X,Y,Z , V , Xq,Yq,Zq ) returns interpolated values of a function of three variables at specific query points using linear interpolation. The results always pass through the original sampling of the function. X , Y , and Z contain the coordinates of the sample points.

How to do interpolation between two values? ›

The interpolation equation is as follows: y − y 1 = y 2 − y 1 x 2 − x 1 ( x − x 1 ) , where ( x 1 , y 1 ) and ( x 2 , y 2 ) are two known data points and ("x," "y") represents the data point to be estimated.

How do you correlate two data sets? ›

Here are the steps to take in calculating the correlation coefficient:
  1. Determine your data sets. ...
  2. Calculate the standardized value for your x variables. ...
  3. Calculate the standardized value for your y variables. ...
  4. Multiply and find the sum. ...
  5. Divide the sum and determine the correlation coefficient.
Jul 31, 2023

What is the formula for 2D interpolation in Excel? ›

=INTERPXY(x, y, q, [options]) INTERPXY is a versatile 2D interpolation function based on splines. Use INTERPXY to interpolate from a set of (x,y) data points at an arbitrary point. Use INTERPXY to map a scattered (x,y) data points onto a uniform grid for easy plotting in Excel.

What is 2D interpolation origin? ›

2D Interpolation/Extrapolation allows you to interpolate/extrapolate either on a group of existing XYZ data for a given XY dataset or a specified matrix object.

What is the interpolation of two lines? ›

Formula of Linear Interpolation

This formula is using coordinates of two given values to find the best fit curve as a straight line. Then this will give any required value of y at a known value of x. In this formula, we are having terms as: x_{1} and y_{1} are the first coordinates.

What is the difference between interpolate and extrapolate? ›

Extrapolation refers to estimating an unknown value based on extending a known sequence of values or facts. To extrapolate is to infer something not explicitly stated from existing information. Interpolation is the act of estimating a value within two known values that exist within a sequence of values.

What is a gridded data? ›

Gridded data is two-dimensional data representing an atmospheric or oceanic parameter along an evenly spaced matrix. For the matrix to be useful, ancillary information about the grid must also be known.

What are the two kinds of approaches in interpolation? ›

There are two main types of interpolation approaches: Deterministic: create surfaces directly from measured points using a weighted distance or area function. Probabilistic (Geostatistical): utilize the statistical properties of the measured points.

How to interpolate gridded data in MATLAB? ›

Use griddedInterpolant to perform interpolation on a 1-D, 2-D, 3-D, or N-D gridded data set. griddedInterpolant returns the interpolant F for the given data set. You can evaluate F at a set of query points, such as (xq,yq) in 2-D, to produce interpolated values vq = F(xq,yq) .

What are the different types of interpolation in MATLAB? ›

1-D and Gridded Interpolation
interp11-D data interpolation (table lookup)
pchipPiecewise Cubic Hermite Interpolating Polynomial (PCHIP)
makimaModified Akima piecewise cubic Hermite interpolation (Since R2019b)
splineCubic spline data interpolation
ppvalEvaluate piecewise polynomial
8 more rows

What is tricubic interpolation? ›

In the mathematical subfield numerical analysis, tricubic interpolation is a method for obtaining values at arbitrary points in 3D space of a function defined on a regular grid. The approach involves approximating the function locally by an expression of the form. This form has 64 coefficients.

What is the best way to interpolate data? ›

Linear interpolation is the most straightforward and commonly used interpolation method. It comes naturally when we have two points, we connect them with a straight line to fill out the missing information in between. By doing so, we made our assumption that the points on the line represent the unobserved values.

How do you interpolate step by step? ›

How to interpolate
  1. Organize your data. First, put the data you've collected into a chart that shows your independent and dependent variables. ...
  2. Consider creating a graph. ...
  3. Select your two points. ...
  4. Enter values into the interpolation equation. ...
  5. Solve for the missing variable.
Oct 16, 2023

How to interpolate between two data points in Excel? ›

The first way is plugging in the basic mathematical formula for linear interpolation. That formula is:y = y1 + (x - x1) ⨯ (y2 - y1) / (x2 - x1)In this formula, x1, x2, y1 and y2 are all known values. By plugging in a new value for y or x, you can calculate the other coordinate for that value.

What is interpolation of a data set? ›

In short, interpolation is a process of determining the unknown values that lie in between the known data points. It is mostly used to predict the unknown values for any geographical related data points such as noise level, rainfall, elevation, and so on.

Top Articles
Review: In Shane Gillis' Netflix show 'Tires,' the humor doesn't veer far from juvenile
Shane Gillis Netflix Sitcom ‘Tires’ Is a Self-Funded Showcase That Spins Its Wheels: TV Review
Mvd Eagle Ranch Appointment
Otc School Calendar
Wharton County Busted Newspaper
The 8 Best Santa Ynez Wineries to Visit in 2023
Craigslist Richmond Ba
Logo Variations - DreamWorks Animation
Carsavers Rental
Syoss Oleo Intense - 5-10 Cool Bruin - Permanente Haarverf - Haarkleuring - 1 stuk | bol
Faotp Meaning In Text
Belle Fourche Landfill
Icl Urban Dictionary
Dmv Rocklin Wait Times
Gebrauchte New Holland T6.145 Deluxe - Landwirt.com
Rainbird E4C Manual
636-730-9503
Dishonored Subreddit
Closest Dollar Tree Store To My Location
Craigslist.nashville
Baycare Intranet
Pokio.io
Everything to know on series 3 of ITV's The Tower starring Gemma Whelan
Coil Cleaning Lititz
2621 Lord Baltimore Drive
Denise Frazier Leak
Busted Barren County Ky
Horoscope Daily Yahoo
12 30 Pacific Time
Road Conditions Riverton Wy
Coverwood Terriers For Sale
Gracex Rayne
Western Lake Erie - Lake Erie and Lake Ontario
Espn Chargers Depth Chart
Charlotte North Carolina Craigslist Pets
Paola Iezzi, chi è il compagno. L’uomo in comune con la sorella Chiara e le nozze 'congelate'
Tires Shop Santoyo
Sound Ideas, TAKE, CARTOON - WHISTLE TAKE/Image Gallery
Brooklyn Park City Hall
Edenmodelsva
Rabbi Raps
Kronos.nyp
Antonin Balthazar Lévy
5 Pros & Cons of Massage Envy (VS Independent Massage Therapists)
Hotels Near William Woollett Jr Aquatics Center
Gotham Chess Twitter
Fintechzoommortgagecalculator.live Hours
Level A Sarasota
Sarah Colman-Livengood Park Raytown Photos
29+ Des Moines Craigslist Furniture
FINAL FANTASY XI Online 20th Anniversary | Square Enix Blog
Latest Posts
Article information

Author: Sen. Emmett Berge

Last Updated:

Views: 6515

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Sen. Emmett Berge

Birthday: 1993-06-17

Address: 787 Elvis Divide, Port Brice, OH 24507-6802

Phone: +9779049645255

Job: Senior Healthcare Specialist

Hobby: Cycling, Model building, Kitesurfing, Origami, Lapidary, Dance, Basketball

Introduction: My name is Sen. Emmett Berge, I am a funny, vast, charming, courageous, enthusiastic, jolly, famous person who loves writing and wants to share my knowledge and understanding with you.