Interpolate Vertices Between Known Data Points

This example shows how to interpolate values in a set of vertices using the interpm function. In this example, you specify that no gap greater than 1 degree should exist between existing vertices, as specified by the maxdiff parameter. See interpm for more information.

Define two vectors containing the latitude and longitude values for a set of vertices. In lat, note that a gap of 2 degrees exists between the values 2 and 4. Similarly, in lon, a gap of 2 degrees exists between the values 1 and the 3.

lat = [1 2 4 5]; 
lon = [1 3 4 5];

Call interpm to fill in any gaps greater than 1 degree in either vector. For example, interpm interpolates and inserts the value 2 into the lon vector to fill the gap between the values 1 and 3, and inserts the value 1.5 in the lat vector for this new vertex. Similarly, interpm inserts the value 3 into the lat vector to fill the gap between the values 2 and 4, and inserts the value 3.5 in the lon vector for this new vertex. Now, the separation of adjacent vertices is no greater than maxdiff in either newlat or newlon.

maxdiff = 1;
[newlat,newlon] = interpm(lat,lon,maxdiff)
newlat = 6×1

    1.0000
    1.5000
    2.0000
    3.0000
    4.0000
    5.0000

newlon = 6×1

    1.0000
    2.0000
    3.0000
    3.5000
    4.0000
    5.0000