Main Content


Interpolate between waypoints on regular data grid


[zi,ri,lat,lon] = mapprofile
[zi,ri,lat,lon] = mapprofile(Z,R,lat,lon)
[zi,ri,lat,lon] = mapprofile(Z,R,lat,lon,units)
[zi,ri,lat,lon] = mapprofile(Z,R,lat,lon,ellipsoid)
[zi,ri,lat,lon] = mapprofile(___,'trackmethod','interpmethod')


mapprofile plots a profile of values between waypoints on a displayed regular data grid. mapprofile uses the current object if it is a regular data grid, or the first regular data grid found on the current axes. The grid's zdata is used for the profile. The color data is used in the absence of zdata. The result is displayed in a new figure.

[zi,ri,lat,lon] = mapprofile returns the values of the profile without displaying them. The output zi contains interpolated values along great circles between the waypoints. ri is a vector of associated distances from the first waypoint in units of degrees of arc along the surface. lat and lon are the corresponding latitudes and longitudes.

[zi,ri,lat,lon] = mapprofile(Z,R,lat,lon) accepts as input a regular data grid and waypoint vectors. No displayed grid is required. Sets of waypoints may be separated by NaNs into line sequences. The output ranges are measured from the first waypoint within a sequence. R can be a geographic raster reference object, a referencing vector, or a referencing matrix.

If R is a geographic raster reference object, its RasterSize property must be consistent with size(Z).

If R is a referencing vector, it must be a 1-by-3 with elements:

[cells/degree northern_latitude_limit western_longitude_limit]

If R is a referencing matrix, it must be 3-by-2 and transform raster row and column indices to or from geographic coordinates according to:

[lon lat] = [row col 1] * R

If R is a referencing matrix, it must define a (non-rotational, non-skewed) relationship in which each column of the data grid falls along a meridian and each row falls along a parallel.

[zi,ri,lat,lon] = mapprofile(Z,R,lat,lon,units) specifies the units of the output ranges along the profile. Valid range units inputs are any distance value recognized by unitsratio. Surface distances are computed using the default radius of the earth. If omitted, 'degrees' are assumed.

[zi,ri,lat,lon] = mapprofile(Z,R,lat,lon,ellipsoid) uses the provided ellipsoid definition in computing the range along the profile. ellipsoid is a referenceSphere, referenceEllipsoid, or oblateSpheroid object, or a vector of the form [semimajor_axis eccentricity]. The output range is reported in the same distance units as the semimajor axes of the ellipsoid. If you do not specify ellipsoid and R is a reference object with a nonempty GeographicCRS property, then mapprofile uses the ellipsoid contained in the Spheroid property of the geocrs object in the GeographicCRS property of R. Otherwise, mapprofile uses the unit sphere.

[zi,ri,lat,lon] = mapprofile(___,'trackmethod','interpmethod') control the interpolation methods used. Valid track methods are 'gc' for great circle tracks between waypoints, and 'rh' for rhumb lines. Valid methods for interpolation within the matrix are 'bilinear' for linear interpolation, 'bicubic' for cubic interpolation, and 'nearest' for nearest neighbor interpolation. If omitted, 'gc' and 'bilinear' are assumed.


collapse all

Load elevation raster data and a geographic cells reference object for the Korean peninsula. Specify an elevation profile. Then, plot the profile along with coastline and city marker data. When you select more than two waypoints, the automatically generated figure displays the result in 3-D.

load korea5c
plat = [ 43  43  41  38];
plon = [116 120 126 128];
load coastlines
geoshow('worldcities.shp','Marker','.','Color', 'red')

3-D map with elevation profile, coastlines, and city markers

This example shows the relative sizes of the mountains in northern China (upper-left) compared to the depths of the Sea of Japan (lower-right).

First, load elevation raster data and a geographic cells reference object for the Korean peninsula. Create a map axes object with appropriate limits and display the data as a surface. Then, interactively pick waypoints by calling mapprofile without input arguments. Select the two waypoints, one in the upper-left corner and one in the lower-right corner, by clicking your mouse. Press Enter after you select the last point.

load korea5c
[zi,ri,lat,lon] = mapprofile;

Map showing elevation data for the Korean peninsula

When you call mapprofile using output arguments, the results do not display in a new figure. Instead, use the results in further calculations or display the results yourself. For this example, convert ranges and elevations to kilometers and display them in a new figure. Set the vertical exaggeration factor to 50. Otherwise, the changes in elevation would be almost too small to see.

daspect([ 1 1/50 1 ]);
xlabel 'Range (km)'
ylabel 'Elevation (km)'

Plot showing relationship between range and elevation in kilometers

The profile you get depends on the transect locations you pick.

You can compute values along a path without reference to an existing figure by providing a regular data grid and vectors of waypoint coordinates. Optional arguments allow control over the units of the range output and interpolation methods between waypoints and data grid elements.

Show what land and ocean areas lie under a great circle track from Frankfurt to Seattle:

cities = shaperead('worldcities.shp', 'UseGeoCoords', true);
Seattle = strcmp('Seattle', {cities(:).Name});
Frankfurt = strcmp('Frankfurt', {cities(:).Name});
lat = [cities(Seattle).Lat cities(Frankfurt).Lat];
lon = [cities(Seattle).Lon cities(Frankfurt).Lon];
load topo60c
[valp,rp,latp,lonp] = ...
   mapprofile(topo60c,topo60cR, ...
worldmap([40 80],[-135 20])
land = shaperead('landareas.shp', 'UseGeoCoords', true);
faceColors = makesymbolspec('Polygon',...
   {'INDEX', [1 numel(land)], 'FaceColor', ...
axis off

World map showing great circle path from Frankfurt to Seattle

Load elevation data and a geographic cells reference object for the Korean peninsula. View the region on geographic axes using a satellite basemap.

load korea5c

Define endpoints for a straight-line transect through the region. Compute the elevation profile by using the mapprofile function. By default, the mapprofile function uses bilinear interpolation along a great circle track.

plat = [40.5 30.7];
plon = [121.5 133.5];
[z,rng,lat,lon] = mapprofile(korea5c,korea5cR,plat,plon);

Preserve the basemap and limits by using hold on. Plot the transect on the geographic axes.

hold on

Plot the transect range and elevation on Cartesian axes.


See Also