Interpolate 2-D or 3-D scattered data (2024)

Interpolate 2-D or 3-D scattered data

collapse all in page

Syntax

vq = griddata(x,y,v,xq,yq)

vq = griddata(x,y,z,v,xq,yq,zq)

vq = griddata(___,method)

[Xq,Yq,vq] = griddata(x,y,v,xq,yq)

[Xq,Yq,vq] = griddata(x,y,v,xq,yq,method)

Description

example

vq = griddata(x,y,v,xq,yq) fitsa surface of the form v = f(x,y) tothe scattered data in the vectors (x,y,v). The griddata functioninterpolates the surface at the query points specified by (xq,yq) andreturns the interpolated values, vq. The surfacealways passes through the data points defined by x and y.

example

vq = griddata(x,y,z,v,xq,yq,zq) fitsa hypersurface of the form v = f(x,y,z).

vq = griddata(___,method) specifies the interpolation method used to compute vq using any of the input arguments in the previous syntaxes. method can be "linear", "nearest", "natural", "cubic", or "v4". The default method is "linear".

[Xq,Yq,vq] = griddata(x,y,v,xq,yq) and [Xq,Yq,vq] = griddata(x,y,v,xq,yq,method) additionally return Xq and Yq, which contain the grid coordinates for the query points.

Examples

collapse all

Interpolate Scattered Data over Uniform Grid

Open Live Script

Interpolate random scattered data on a uniform grid of query points.

Sample a function at 200 random points between -2.5 and 2.5. The resulting vectors x, y, and v contain scattered sample points and data values at those points.

rng defaultxy = -2.5 + 5*rand([200 2]);x = xy(:,1);y = xy(:,2);v = x.*exp(-x.^2-y.^2);

Define a grid of query points and interpolate the scattered data over the grid.

[xq,yq] = meshgrid(-2:.2:2, -2:.2:2);vq = griddata(x,y,v,xq,yq);

Plot the gridded data as a mesh and the scattered data as dots.

mesh(xq,yq,vq)hold onplot3(x,y,v,"o")xlim([-2.7 2.7])ylim([-2.7 2.7])

Interpolate 4-D Data Set over Grid

Open Live Script

Interpolate a 3-D slice of a 4-D function that is sampled at randomly scattered points.

Sample a 4-D function v(x,y,z) at 2500 random points between -1 and 1. The vectors x, y, and z contain the nonuniform sample points.

x = 2*rand(2500,1) - 1; y = 2*rand(2500,1) - 1; z = 2*rand(2500,1) - 1;v = x.^2 + y.^3 - z.^4;

Create a grid with xy points in the range [-1, 1], and set z=0. Interpolating on this grid of 2-D query points (xq,yq,0) produces a 3-D interpolated slice (xq,yq,0,vq) of the 4-D data set (x,y,z,v).

d = -1:0.05:1;[xq,yq,zq] = meshgrid(d,d,0);

Interpolate the scattered data on the grid. Plot the results.

vq = griddata(x,y,z,v,xq,yq,zq);plot3(x,y,v,"ro")hold onsurf(xq,yq,vq)hold off

Interpolate 2-D or 3-D scattered data (2)

Comparison of Scattered Data Interpolation Methods

Open Live Script

Compare the results of several different interpolation algorithms offered by griddata.

Create a sample data set of 50 scattered points. The number of points is artificially small to highlight the differences between the interpolation methods.

x = -3 + 6*rand(50,1);y = -3 + 6*rand(50,1);v = sin(x).^4 .* cos(y);

Create a grid of query points.

[xq,yq] = meshgrid(-3:0.1:3);

Interpolate the sample data using the "nearest", "linear", "natural", and "cubic" methods. Plot the results for comparison.

z1 = griddata(x,y,v,xq,yq,"nearest");plot3(x,y,v,"mo")hold onmesh(xq,yq,z1)title("Nearest Neighbor")legend("Sample Points","Interpolated Surface","Location","NorthWest")

Interpolate 2-D or 3-D scattered data (3)

z2 = griddata(x,y,v,xq,yq,"linear");figureplot3(x,y,v,"mo")hold onmesh(xq,yq,z2)title("Linear")legend("Sample Points","Interpolated Surface","Location","NorthWest")

Interpolate 2-D or 3-D scattered data (4)

z3 = griddata(x,y,v,xq,yq,"natural");figureplot3(x,y,v,"mo")hold onmesh(xq,yq,z3)title("Natural Neighbor")legend("Sample Points","Interpolated Surface","Location","NorthWest")
z4 = griddata(x,y,v,xq,yq,"cubic");figureplot3(x,y,v,"mo")hold onmesh(xq,yq,z4)title("Cubic")legend("Sample Points","Interpolated Surface","Location","NorthWest")

Interpolate 2-D or 3-D scattered data (6)

Plot the exact solution.

figureplot3(x,y,v,"mo")hold onmesh(xq,yq,sin(xq).^4 .* cos(yq))title("Exact Solution")legend("Sample Points","Exact Surface","Location","NorthWest")

Interpolate 2-D or 3-D scattered data (7)

Input Arguments

collapse all

x, y, zSample point coordinates
vectors

Sample point coordinates, specified as vectors. Correspondingelements in x, y, and z specifythe xyz coordinates of points where the samplevalues v are known. The sample points must be unique.

Data Types: double

vSample values
vector

Sample values, specified as a vector. The sample values in v correspondto the sample points in x, y,and z.

If v contains complex numbers, then griddata interpolatesthe real and imaginary parts separately.

Data Types: double
Complex Number Support: Yes

xq, yq, zqQuery points
vector | array

Query points, specified as vectors or arrays. Correspondingelements in the vectors or arrays specify the xyz coordinatesof the query points. The query points are the locations where griddata performsinterpolation.

  • Specify arrays if you want to pass a grid of querypoints. Use ndgrid or meshgrid to construct the arrays.

  • Specify vectors if you want to pass a collection of scattered points.

The specified query points must lie inside the convex hull ofthe sample data points. griddata returns NaN forquery points outside of the convex hull.

Data Types: double

methodInterpolation method
"linear" (default) | "nearest" | "natural" | "cubic" | "v4"

Interpolation method, specified as one of the methods in thistable.

MethodDescriptionContinuity
"linear"Triangulation-based linear interpolation (default) supporting2-D and 3-D interpolation.C0
"nearest"Triangulation-based nearest neighbor interpolation supporting2-D and 3-D interpolation.Discontinuous
"natural"Triangulation-based natural neighbor interpolation supporting2-D and 3-D interpolation. This method is an efficient tradeoff betweenlinear and cubic.C1 except at sample points
"cubic"Triangulation-based cubic interpolation supporting 2-D interpolationonly.C2
"v4"

Biharmonic spline interpolation (MATLAB® 4 griddata method)supporting 2-D interpolation only. Unlike the other methods, thisinterpolation is not based on a triangulation.

C2

Data Types: char | string

Output Arguments

collapse all

vq — Interpolated values
vector | array

Interpolated values, returned as a vector or array. The sizeof vq depends on the size of the query point inputs xq, yq,and zq:

  • For 2-D interpolation, where xq and yq specifyan m-by-n grid of query points, vq isan m-by-n array.

  • For 3-D interpolation, where xq, yq,and zq specify an m-by-n-by-p gridof query points, vq is an m-by-n-by-p array.

  • If xq, yq, (and zq for3-D interpolation) are vectors that specify scattered points, then vq isa vector of the same length.

For all interpolation methods other than "v4", the output vq contains NaN values for query points outside the convex hull of the sample data. The "v4" method performs the same calculation for all points regardless of location.

Xq, Yq — Grid coordinates for query points
vectors | matrices

Grid coordinates for query points, returned as vectors or matrices. The shape of Xq and Yq depends on how you specify xq and yq:

  • If you specify xq as a row vector and yq as a column vector, then griddata uses those grid vectors to form a full grid with [Xq,Yq] = meshgrid(xq,yq). In this case, the Xq and Yq outputs are returned as matrices that contain the full grid coordinates for the query points.

  • If xq and yq are both row vectors or both column vectors, then Xq = xq and Yq = yq.

Tips

  • Scattered data interpolation with griddata uses a Delaunay triangulation of the data, so can be sensitive to scaling issues in x, y, and z. When this occurs, you can use normalize to rescale the data and improve the results. See Normalize Data with Differing Magnitudes for more information.

Extended Capabilities

Version History

Introduced before R2006a

See Also

scatteredInterpolant | delaunay | griddatan | interpn | meshgrid | ndgrid

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.

Interpolate 2-D or 3-D scattered data (8)

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

Interpolate 2-D or 3-D scattered data (2024)

FAQs

How do you interpolate in scattered data? ›

Linear interpolation of scattered data requires a mesh to be constructed using known independent points. This can be done using Delaunay triangulation to obtain simplexes (triangles or their higher dimensional equivalents) for the interpolation function to be applied over.

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 know whether you interpolated or extrapolated data? ›

Extra- refers to "in addition to," while inter- means "in between." Thus, extrapolation indicates a user is trying to find a value in addition to existing values, while interpolation means that they want to determine a new value in between existing values.

What is the best data interpolation method? ›

Radial Basis Function interpolation is a diverse group of data interpolation methods. In terms of the ability to fit your data and produce a smooth surface, the Multiquadric method is considered by many to be the best.

How do you analyze scattered data? ›

Here's what to look for when evaluating a scatter plot: Assess the data distribution for trends, gaps, or clusters. Or simply where a relationship exists between two numeric variables within the data set. Use linear regression analysis to capture relationships between variables.

What is the easiest method for solving interpolation? ›

One of the simplest methods is linear interpolation (sometimes known as lerp). Consider the above example of estimating f(2.5). Since 2.5 is midway between 2 and 3, it is reasonable to take f(2.5) midway between f(2) = 0.9093 and f(3) = 0.1411, which yields 0.5252.

Which interpolation formula is better? ›

If linear interpolation formula is concerned then it can be used to find the new value from the two given points. If we compare it to Lagrange's interpolation formula, the “n” set of numbers is needed. Thereafter Lagrange's method is to be used to find the new value.

What is the fastest interpolation method? ›

The Nearest Point interpolation method is the fastest of all the interpolation methods when used with point data (fig. 19). If used with line or polygon data it can be slower than the Nearest interpolation especially if many of the object vertices lie outside the grid.

What is the simplest method of interpolation? ›

One of the simplest methods, linear interpolation, requires knowledge of two points and the constant rate of change between them. With this information, you may interpolate values anywhere between those two points.

When not to use extrapolation? ›

First Warning: Avoid Extrapolation

Remember not all relationships are linear (most are not) so when we look at a scatterplot we can only confirm that there is a linear pattern within the range of data at hand. The pattern may very well change shapes outside that range so using a line for extrapolation is inappropriate.

How to calculate interpolation? ›

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.

Is extrapolated data accurate? ›

It gives good results when the predicted value is close to the available data but can be more accurate when it is far from the available data. It is because linear extrapolation assumes that there will be no change in the relationship between two variables as you go farther away from their current values.

What is the most accurate method of interpolation? ›

In conclusion, computation is the best method for interpolating contour lines. This involves using mathematical formulas and algorithms to estimate the value of the contour line at a point. Linear interpolation, polynomial interpolation, and kriging are all effective methods of computational interpolation.

What is the optimal interpolation method? ›

Optimal interpolation is a commonly used method for data assimilation. It combines theory (background data) with observations. It can be used to merge and interpolate measurements of the same variable, such as elevation or precipitation, from different data sources.

Which interpolation or extrapolation generally gives a more accurate prediction? ›

Interpolation is typically more reliable than extrapolation, but both types of prediction can be useful for different purposes. There are multiple methods you can use to conduct either interpolation or extrapolation, such as linear and polynomial methods of prediction.

What are the interpolation techniques used for evenly spaced data? ›

Linear interpolation is often used to regrid evenly-spaced data, such as longitude / latitude gridded data, to a higher or lower resolution.

What is the interpolation of spreads? ›

The I-spread stands for interpolated spread. It represents the difference between the yield on a bond and the swap rate (the interest rate applicable to the fixed leg in the floating-for-fixed interest rate swap, say, LIBOR). A higher I-spread means that a bond has a higher credit risk.

What are interpolations and extrapolations based on a scatterplot? ›

The difference between these two words is actually quite simple. Interpolation is where you use the line of best fit for a value that is within the plotted points. Extrapolation is where you use the line of best fit for a value that is outside the plotted points. In other words, you have extended the pattern.

How to 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.

Top Articles
Refresh Your Camper with These RV Decorating Ideas - RV Expertise
RV Decorating Ideas that Will Help Make your RV Feel Like Home
Spasa Parish
Rentals for rent in Maastricht
159R Bus Schedule Pdf
Sallisaw Bin Store
Zachary Zulock Linkedin
Www.myschedule.kp.org
Ascension St. Vincent's Lung Institute - Riverside
Understanding British Money: What's a Quid? A Shilling?
Xenia Canary Dragon Age Origins
Momokun Leaked Controversy - Champion Magazine - Online Magazine
Maine Coon Craigslist
‘An affront to the memories of British sailors’: the lies that sank Hollywood’s sub thriller U-571
Tyreek Hill admits some regrets but calls for officer who restrained him to be fired | CNN
Haverhill, MA Obituaries | Driscoll Funeral Home and Cremation Service
Rogers Breece Obituaries
Ems Isd Skyward Family Access
Elektrische Arbeit W (Kilowattstunden kWh Strompreis Berechnen Berechnung)
Omni Id Portal Waconia
Kellifans.com
Banned in NYC: Airbnb One Year Later
Four-Legged Friday: Meet Tuscaloosa's Adoptable All-Stars Cub & Pickle
Model Center Jasmin
Ice Dodo Unblocked 76
Is Slatt Offensive
Labcorp Locations Near Me
Storm Prediction Center Convective Outlook
Experience the Convenience of Po Box 790010 St Louis Mo
Fungal Symbiote Terraria
modelo julia - PLAYBOARD
Poker News Views Gossip
Abby's Caribbean Cafe
Joanna Gaines Reveals Who Bought the 'Fixer Upper' Lake House and Her Favorite Features of the Milestone Project
Tri-State Dog Racing Results
Navy Qrs Supervisor Answers
Trade Chart Dave Richard
Lincoln Financial Field Section 110
Free Stuff Craigslist Roanoke Va
Stellaris Resolution
Wi Dept Of Regulation & Licensing
Pick N Pull Near Me [Locator Map + Guide + FAQ]
Crystal Westbrooks Nipple
Ice Hockey Dboard
Über 60 Prozent Rabatt auf E-Bikes: Aldi reduziert sämtliche Pedelecs stark im Preis - nur noch für kurze Zeit
Wie blocke ich einen Bot aus Boardman/USA - sellerforum.de
Infinity Pool Showtimes Near Maya Cinemas Bakersfield
Dermpathdiagnostics Com Pay Invoice
How To Use Price Chopper Points At Quiktrip
Maria Butina Bikini
Busted Newspaper Zapata Tx
Latest Posts
Article information

Author: Domingo Moore

Last Updated:

Views: 5870

Rating: 4.2 / 5 (73 voted)

Reviews: 88% of readers found this page helpful

Author information

Name: Domingo Moore

Birthday: 1997-05-20

Address: 6485 Kohler Route, Antonioton, VT 77375-0299

Phone: +3213869077934

Job: Sales Analyst

Hobby: Kayaking, Roller skating, Cabaret, Rugby, Homebrewing, Creative writing, amateur radio

Introduction: My name is Domingo Moore, I am a attractive, gorgeous, funny, jolly, spotless, nice, fantastic person who loves writing and wants to share my knowledge and understanding with you.