Interpolating Gridded Data - MATLAB & Simulink (2024)

Interpolating Gridded Data

Gridded data consists of values or measurements at regularly spaced points that form a grid. Gridded data arises in many areas, such as meteorology, surveying, and medical imaging. In these areas, it is common to take measurements at regular spatial intervals, possibly over time. These ordered grids of data can range from 1-D (for simple time series) to 4-D (for measuring volumes over time) or higher. Some examples of gridded data are:

  • 1-D: Stock prices over time

  • 2-D: Temperature of a surface

  • 3-D: MRI image of a brain

  • 4-D: Ocean measurements in a volume of water over time

In all of these applications, grid-based interpolation efficiently extends the usefulness of the data to points where no measurement was taken. For example, if you have hourly price data for a stock, you can use interpolation to approximate the price every 15 minutes.

MATLAB Gridded Interpolation Functions

MATLAB® provides several tools for grid-based interpolation:

Grid Creation Functions

The meshgrid and ndgrid functions create grids of various dimensionality. meshgrid can create 2-D or 3-D grids, while ndgrid can create grids with any number of dimensions. These functions return grids using different output formats. You can convert between these grid formats using the pagetranspose (as of R2020b) or permute functions to swap the first two dimensions of the grid.

Interpolation Functions

The interp family of functions includes interp1, interp2, interp3, and interpn. Each function is designed to interpolate data with a specific number of dimensions. interp2 and interp3 use grids in meshgrid format, while interpn uses grids in ndgrid format.

Interpolation Objects

griddedInterpolant objects support interpolation in any number of dimensions for data in ndgrid format. These objects also support multivalued interpolation (as of R2021a), where each grid point can have multiple values associated with it.

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. Also, griddedInterpolant stores the sample points in a memory-efficient format (as a compact grid) and is multithreaded to take advantage of multicore computer processors.

Grid Representations

MATLAB allows you to represent a grid in one of three representations: full grid, compact grid, or default grid. The default grid and compact grid are used primarily for convenience and improved efficiency, respectively.

Full Grid

A full grid is one in which all points are explicitly defined. The outputs of ndgrid and meshgrid define a full grid. You can create full grids that are uniform, in which points in each dimension have equal spacing, or nonuniform, in which the spacing varies in one or more of the dimensions. Uniform grids can have different spacing in each dimension, as long as the spacing is constant within each dimension.

UniformUniformNonuniform

Interpolating Gridded Data- MATLAB & Simulink (1)

Interpolating Gridded Data- MATLAB & Simulink (2)

Interpolating Gridded Data- MATLAB & Simulink (3)

An example of a uniform full grid is:

[X,Y] = meshgrid([1 2 3],[3 6 9 12])

Compact Grid

Explicitly defining every point in a grid can consume a lot of memory when you are dealing with large grids. The compact grid representation is a way to dispense with the memory overhead of a full grid. The compact grid representation stores only grid vectors (one for each dimension) instead of the full grid. Together, the grid vectors implicitly define the grid. In fact, the inputs for meshgrid and ndgrid are grid vectors, and these functions replicate the grid vectors to form the full grid. The compact grid representation enables you to bypass grid creation and supply the grid vectors directly to the interpolation function.

For example, consider two vectors, x1 = 1:3 and x2 = 1:5. You can think of these vectors as a set of coordinates in the x1 direction and a set of coordinates in the x2 direction, like so:

Interpolating Gridded Data- MATLAB & Simulink (4)

Each arrow points to a location. You can use these two vectors to define a set of grid points, where one set of coordinates is given by x1 and the other set of coordinates is given by x2. When the grid vectors are replicated, they form two coordinate arrays that make up the full grid:

Interpolating Gridded Data- MATLAB & Simulink (5)

Your input grid vectors might be monotonic or nonmonotonic. Monotonic vectors contain values that either increase in that dimension or decrease in that dimension. Conversely, nonmonotonic vectors contain values that fluctuate. If the input grid vector is nonmonotonic, such as [2 4 6 3 1], then [X1,X2] = ndgrid([2 4 6 3 1]) outputs a nonmonotonic grid. Your grid vectors should be monotonic if you intend to pass the grid to other MATLAB functions. The sort function is useful to ensure monotonicity.

Default Grid

In some applications, only the values at the grid points are important and not the distances between grid points. For example, most MRI scans gather data that is uniformly spaced in all directions. In cases like this, you can allow the interpolation function to automatically generate a default grid representation to use with the data. To do this, leave out the grid inputs to the interpolation function. When you leave out the grid inputs, the function automatically considers the data to be on a unit-spaced grid. The function creates this unit-spaced grid while it executes, saving you the trouble of creating a grid yourself.

Example: Temperature Interpolation on 2-D Grid

Consider temperature data collected on a surface at regular 5 cm intervals, extending 20 cm in each direction. Use meshgrid to create the full grid.

[X,Y] = meshgrid(0:5:20)
X = 0 5 10 15 20 0 5 10 15 20 0 5 10 15 20 0 5 10 15 20 0 5 10 15 20Y = 0 0 0 0 0 5 5 5 5 5 10 10 10 10 10 15 15 15 15 15 20 20 20 20 20

The (x,y) coordinates of each grid point are represented as corresponding elements in the X and Y matrices. The first grid point is given by [X(1) Y(1)], which is [0 0], the next grid point is given by [X(2) Y(2)], which is [0 5], and so on.

Now, create a matrix to represent temperature measurements on the grid and then plot the data as a surface.

T = [1 1 10 1 1; 1 10 10 10 10; 100 100 1000 100 100; 10 10 10 10 1; 1 1 10 1 1];surf(X,Y,T)view(2)

Interpolating Gridded Data- MATLAB & Simulink (6)

Although the temperature at the center grid point is large, its location and influence on surrounding grid points is not apparent from the raw data.

To improve the resolution of the data by a factor of 10, use interp2 to interpolate the temperature data onto a finer grid that uses 0.5 cm intervals. Use meshgrid again to create a finer grid represented by the matrices Xq and Yq. Then, use interp2 with the original grid, the temperature data, and the new grid points, and plot the resulting data. By default, interp2 uses linear interpolation in each dimension.

[Xq,Yq] = meshgrid(0:0.5:20);Tq = interp2(X,Y,T,Xq,Yq);surf(Xq,Yq,Tq)view(2)

Interpolating Gridded Data- MATLAB & Simulink (7)

Interpolating the temperature data adds detail to the image and greatly improves the usefulness of the data within the area of measurements.

Gridded Interpolation Methods

The grid-based interpolation functions and objects in MATLAB offer several different methods for interpolation. When choosing an interpolation method, keep in mind that some require more memory or longer computation time than others. You may need to trade off these resources to achieve the desired smoothness in the result. The following table gives a preview of each interpolation method applied to the same 1-D data, and also provides an overview of the benefits, trade-offs, and requirements for each method.

MethodDescription

Interpolating Gridded Data- MATLAB & Simulink (8)

The interpolated value at a query point is the value at the nearest sample grid point.

  • Discontinuous

  • Modest memory requirements

  • Fastest computation time

  • Requires 2 grid points in each dimension

Interpolating Gridded Data- MATLAB & Simulink (9)

The interpolated value at a query point is the value at the next sample grid point.

  • Discontinuous

  • Same memory requirements and computation time as nearest neighbor

  • Available for 1-D interpolation only

  • Requires at least 2 grid points

Interpolating Gridded Data- MATLAB & Simulink (10)

The interpolated value at a query point is the value at the previous sample grid point.

  • Discontinuous

  • Same memory requirements and computation time as nearest neighbor

  • Available for 1-D interpolation only

  • Requires at least 2 grid points

Interpolating Gridded Data- MATLAB & Simulink (11)

The interpolated value at a query point is based on linear interpolation of the values at neighboring grid points in each respective dimension.

  • C0 continuous

  • Requires more memory and computation time than nearest neighbor

  • Requires at least 2 grid points in each dimension

Interpolating Gridded Data- MATLAB & Simulink (12)

The interpolated value at a query point is based on a shape-preserving piece-wise cubic interpolation of the values at neighboring grid points.

  • C1 continuous

  • Requires more memory and computation time than linear

  • Available for 1-D interpolation only

  • Requires at least 4 grid points

Interpolating Gridded Data- MATLAB & Simulink (13)

The interpolated value at a query point is based on cubic interpolation of the values at neighboring grid points in each respective dimension.

  • C1 continuous

  • Requires more memory and computation time than linear

  • Grid must have uniform spacing, though the spacing in each dimension does not have to be the same

  • Requires at least 4 points in each dimension

Interpolating Gridded Data- MATLAB & Simulink (14)

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 continuous

  • Similar memory requirements as spline

  • Requires more computation time than cubic, but typically less than spline

  • Requires at least 2 grid points in each dimension

Interpolating Gridded Data- MATLAB & Simulink (15)

The interpolated value at a query point is based on a cubic interpolation of the values at neighboring grid points in each respective dimension.

  • C2 continuous

  • Requires more memory and computation time than cubic

  • Requires at least 4 points in each dimension

See Also

interp1 | interp2 | interp3 | interpn | griddedInterpolant

Related Topics

  • Resample Image with Gridded Interpolation
  • Interpolation of Multiple 1-D Value Sets
  • Interpolation of 2-D Selections in 3-D Grids

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.

Interpolating Gridded Data- MATLAB & Simulink (16)

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

Interpolating Gridded Data
- MATLAB & Simulink (2024)

FAQs

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) .

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.

What is the difference between griddedInterpolant and interp1? ›

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.

Does MATLAB have an interpolation function? ›

You can use interpolation to fill-in missing data, smooth existing data, make predictions, and more. Interpolation in MATLAB® is divided into techniques for data points on a grid and scattered data points.

How do you interpolate 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.

How to use data from MATLAB in Simulink? ›

To load data for a bus, set the Output data type to Bus: <bus object> and specify the name of the Simulink. Bus object that defines the output bus. To load enumerated data, set the Output data type to Enum: <class name> and specify the name of the enumeration class that defines the enumerated data values.

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 to use MATLAB with Simulink? ›

Create a Simulink Model
  1. In the MATLAB® Home tab, click the Simulink button.
  2. Click Blank Model, and then Create Model. ...
  3. On the Simulation tab, click Library Browser.
  4. In the Library Browser: ...
  5. Make the following block-to-block connections: ...
  6. Double-click the Transfer Fcn block. ...
  7. Double-click the Signal Generator block.

What is the interpolation toolbox in MATLAB? ›

Interpolation is a method of estimating values between known data points. Use interpolation to smooth observed data, fill in missing data, and make predictions. Curve Fitting Toolbox™ functions allow you to perform interpolation by fitting a curve or surface to the data.

How do you interpolate a surface in MATLAB? ›

The griddata function interpolates the surface at the query points specified by (xq,yq) and returns the interpolated values, vq . The surface always passes through the data points defined by x and y . vq = griddata( x , y , z , v , xq , yq , zq ) fits a hypersurface of the form v = f(x,y,z).

What is 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.

How to extrapolate data in MATLAB? ›

Selecting an Extrapolation Method
  1. Generate data or load data into the workspace.
  2. Open the Curve Fitter app by entering curveFitter at the MATLAB command line. ...
  3. In the Curve Fitter app, select curve data. ...
  4. Click the arrow in the Fit Type section to open the gallery, and click Interpolant in the Interpolation group.

What to use instead of interp1d? ›

interp1d is considered legacy API and is not recommended for use in new code. Consider using more specific interpolators instead. The 'cubic' kind of interp1d is equivalent to make_interp_spline , and the 'linear' kind is equivalent to numpy. interp while also allowing N-dimensional y arrays.

What does interp1 do in MATLAB? ›

For faster interpolation when x is equally spaced, use the methods ' * linear' , ' * cubic' , ' * nearest' , or ' * spline' . The interp1 command interpolates between data points. It finds values of a one-dimensional function f(x) underlying the data at intermediate points.

How do you interpolate data on a graph? ›

We could use our graph to interpolate the volume for a sample with a mass of 2.5 g. This is done by drawing a vertical line from the x-axis at a value of 2.5 g until it crosses our best fit line, and then drawing a horizontal line to the y-axis. The y-value at this point, 4.9 ml, is equal to the volume of 2.5 g sample.

How to interpolate 1d data in MATLAB? ›

vq = interp1( x , v , xq ) returns interpolated values of a 1-D function at specific query points using linear interpolation. Vector x contains the sample points, and v contains the corresponding values, v(x). Vector xq contains the coordinates of the query points.

How do you interpolate a scatter plot in MATLAB? ›

To interpolate using a single set of values, specify v as a vector, where the number of rows is the same as the number of sample points. To interpolate using multiple sets of values, specify v as a matrix, where the number of rows is the same as the number of sample points.

References

Top Articles
How to Use DRAM Calculator (Easy and Straightforward) - Hardware Centric
DRAM Calculator for Ryzen 1.7.2 – what is new?
$4,500,000 - 645 Matanzas CT, Fort Myers Beach, FL, 33931, William Raveis Real Estate, Mortgage, and Insurance
Tryst Utah
Television Archive News Search Service
It may surround a charged particle Crossword Clue
Week 2 Defense (DEF) Streamers, Starters & Rankings: 2024 Fantasy Tiers, Rankings
Valley Fair Tickets Costco
³µ¿Â«»ÍÀÇ Ã¢½ÃÀÚ À̸¸±¸ ¸íÀÎ, ¹Ì±¹ Ķ¸®Æ÷´Ï¾Æ ÁøÃâ - ¿ù°£ÆÄ¿öÄÚ¸®¾Æ
Evil Dead Rise Showtimes Near Massena Movieplex
Emmalangevin Fanhouse Leak
Gw2 Legendary Amulet
Osrs But Damage
Nioh 2: Divine Gear [Hands-on Experience]
Hoe kom ik bij mijn medische gegevens van de huisarts? - HKN Huisartsen
Crossword Nexus Solver
Truck Trader Pennsylvania
111 Cubic Inch To Cc
Gemita Alvarez Desnuda
Lowe's Garden Fence Roll
360 Tabc Answers
Nine Perfect Strangers (Miniserie, 2021)
Account Suspended
Jet Ski Rental Conneaut Lake Pa
What Channel Is Court Tv On Verizon Fios
Drug Test 35765N
Cookie Clicker Advanced Method Unblocked
Play Tetris Mind Bender
Il Speedtest Rcn Net
Booknet.com Contract Marriage 2
Jackie Knust Wendel
Infinite Campus Asd20
Darknet Opsec Bible 2022
Amazing Lash Bay Colony
Redbox Walmart Near Me
Maybe Meant To Be Chapter 43
Best Weapons For Psyker Darktide
Otter Bustr
Regis Sectional Havertys
Mandy Rose - WWE News, Rumors, & Updates
Stafford Rotoworld
Convenient Care Palmer Ma
Сталь aisi 310s российский аналог
Guy Ritchie's The Covenant Showtimes Near Grand Theatres - Bismarck
Trivago Anaheim California
Former Employees
Pike County Buy Sale And Trade
John M. Oakey & Son Funeral Home And Crematory Obituaries
Stosh's Kolaches Photos
Centimeters to Feet conversion: cm to ft calculator
Diamond Desires Nyc
Att Corporate Store Location
Latest Posts
Article information

Author: Kelle Weber

Last Updated:

Views: 5826

Rating: 4.2 / 5 (73 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Kelle Weber

Birthday: 2000-08-05

Address: 6796 Juan Square, Markfort, MN 58988

Phone: +8215934114615

Job: Hospitality Director

Hobby: tabletop games, Foreign language learning, Leather crafting, Horseback riding, Swimming, Knapping, Handball

Introduction: My name is Kelle Weber, I am a magnificent, enchanting, fair, joyous, light, determined, joyous person who loves writing and wants to share my knowledge and understanding with you.