MATLAB Examples

Plot latitude and longitude.

Maps the figure of the Earth using the geoid data set.

Use the Mapping Toolbox to create a world map. Geospatial data can be voluminous, complex, and difficult to process. Mapping Toolbox functions handle many of the details of loading and

Transform a regular data grid into a new one with its data rearranged to correspond to a new coordinate system using the neworig function. You can transform coordinate systems of data grids as

You can create UTM maps with axesm , just like any other projection. However, unlike other projections, the map frame is limited to an 8-by-6 degree map window (the UTM zone).

To display areas that extend across more than one UTM zone, use the Mercator projection in a transverse aspect. UTM is a zone-based coordinate system and is designed to be used like a map

The best way to gain an understanding of projection aspect is to experiment with orientation vectors. The following example uses a pseudocylindrical projection, the sinusoidal.

Perform the same projection computations that are done within Mapping Toolbox display commands by calling the defaultm and mfwdtran functions.

Add Tissot indicatrices to a map display.

Visualize map projection distortions using isolines (contour lines). Since distortions are rather orderly and vary continuously, they are well-suited for isolines. The mdistort

You can set up UTM to calculate coordinates without generating a map display, using the defaultm function. The utmzone and utmgeoid functions help you select a zone and an appropriate

Convert a USGS DEM into a regular latitude-longitude grid having comparable spatial resolution. U.S. Geological Survey (USGS) 30-meter Digital Elevation Models (DEMs) are regular grids

Register an image to an earth coordinate system and create a new "georeferenced" image. It requires Image Processing Toolbox™ in addition to Mapping Toolbox™.

Analyze the results of logical grid manipulations to determine the area satisfying one or more conditions (either coded as 1s or an expression that yields a logical value of 1). The areamat

Combine raster data and vector data on the same map.

To define a geolocated data grid, you must define three variables: a matrix of indices or values associated with the mapped region, a matrix giving cell-by-cell latitude coordinates, and a

Link line segments into polygons using the polymerge function. polymerge links sets of line segments together by concatenating segments that have matching endpoints. An end point can be

Use the bufferm function to generate a buffer zone internal to a land area polygon. For more information about this topic, see Polygon Buffer Zones .

Trim vectors to form lines and polygons using the maptriml and maptrimp functions. It is not unusual for vector data to extend beyond the geographic region currently of interest. For

Before making a large, memory-taxing data grid, you should first determine what its size will be. If you know the latitude and longitude limits of a region, you can calculate the size of the

Convert vector data to raster data using the vec2mtx function. The example uses patch data for Indiana from the usastatehi shapefile. For more information, see Convert Vector Data to Raster

Overlay polygons using set logic. The polybool function can perform standard set operations, such as intersection, union, subtraction, and exclusive OR, on two sets of vectors, which can

Create a half-resolution version of a georeferenced TIFF image, using referencing objects and Image Processing Toolbox™ functions ind2gray and imresize .

Remove longitude coordinate discontinuities at date line crossings that can confuse set operations on polygons. This can happen when points with longitudes near 180 degrees connect to

Compute an elevation profile along a straight line using the mapprofile function. Calculating data values along a path is a common application when working with gridded geodata. For

Display vector map data and examine vector data values.

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

Calculate the intersections of arbitrary vector data, such as polylines or polygons, using the polyxpoly function.

Simplify polygon and line data using the reducem function. Simplifying polygon and line data can speed up certain calculations without making any noticeable impact on the data. One way to

Generate a shaded relief map using raster data, also known as a data grid. Note that the content, symbolization, and the projection of the map are completely independent. The structure and

Compute the gradient, slope, and aspect for a regular data grid. The gradient components are the change in the grid variable per meter of distance in the north and east directions. Slope is

Interpolate coordinates at specific locations using intrplat and intrplon functions. intrplat and intrplon return one value at a time and give you control over the interpolation method

Identify line or patch segments once they have been combined into large NaN -clipped vectors. You can separate these polygon or line vectors into their component segments using the

How to:

Write data referenced to standard geographic and projected coordinate systems to GeoTIFF files, using geotiffwrite. The Tagged-Image File Format (TIFF) has emerged as a popular format to

Structure geographic point, line, and polygon vector data and export it to a Keyhole Markup Language (KML) file. KML is an XML-based markup language designed for visualizing geographic

To calculate the intersection of vector data, in particular, two small circles. scxsc returns the intersecting points on the circles.

Convert distances along the surface of the Earth (or another planet) from units of kilometers (km), nautical miles (nm), or statute miles (sm) to spherical distances in degrees or radians.

Use the unitsratio function to create a conversion factor for many different units of length, such as microns, millimeters, inches, international feet, and U.S. survey feet. The

Calculate the intersection of rhumb lines using the rhxrh function.

Calculate geographic areas for vector data in polygon format using the areaint function. areaint performs a numerical integration using Green's Theorem for the area on a surface enclosed

Start with a 3-D feature in a system of local east-north-up (ENU) coordinates, then transform and combine it with a globe display in Earth-Centered, Earth-Fixed (ECEF) coordinates.

Generate a true small circle, a loxomdromic small circle, and the limiting case of a great circle.

Create a South-polar Stereographic Azimuthal projection map extending from the South Pole to 20 degrees S, centered on longitude 150 degrees West. Include a value for the Origin property in

Display vector maps as lines or patches (filled-in polygons). Mapping Toolbox functions let you display patch vector data that uses NaNs to separate closed regions.

Create a new regular data grid that covers the region of the geolocated data grid, then embed the color data values into the new matrix. The new matrix might need to have somewhat lower

Manipulate displayed map objects by name. Many functions assign descriptive names to the Tag property of the objects they create. The namem and related functions allow you to control the

Create a range of different maps using mapshow.

Fit gridded data to fine and coarse graticules. The choice of graticule is a balance of speed over precision in terms of positioning the grid on the map. Typically, there is no point to

Combine an elevation data grid and an attribute (color) data grid that cover the same region but are gridded differently. The example drapes slope data from a regular data grid on top of

Create simple maps using the worldmap function. The example uses sample data sets included in the matlabroot/toolbox/map/mapdata folder.

Create a map with a long, narrow, oblique Mercator projection. The example shows the area 10 degrees to either side of the great-circle flight path from Tokyo to New York. You can't use

Create maps of the United States using the usamap function. The usamap function lets you make maps of the United States as a whole, just the conterminous portion (the "lower 48" states),

Change the projection of a map and update the meridian and parallel labels.

Construct an Orthographic projection map with the origin centered near Paris, France. You can't use MapLatLimit or MapLonLimit here.

Specify the map projection origin and frame limits using the two map limit properties: MapLatLimit and MapLonLimit . While the map axes supports properties to set these values directly,

Create a map of the standard version of the Lambert Conformal Conic projection covering latitudes 20 North to 75 North and longitudes covering 90 degrees starting at 30 degrees West.

Create an opaque surface over which you can display line and point data. This can be useful with Globe displays that depict 3-D objects. You can see into and through them as long as no opaque

Set up map axes.

Construct a map of major world cities enhanced with coastlines and terrain. It uses the modified azimuthal Briesemeister map projection. The example includes some optional code that

The figure of the Earth (the geoid data set) draped on topographic relief (the topo data set). The geoid data is shown as an attribute (using a color scale) rather than being depicted as a 3-D

Add a light source to a surface colored data grid. The toolbox manages light objects with the lightm function.

Illustrates how to import and display geographic data that contain coordinates in a projected coordinate reference system.

Create cylindrical projection using map limit properties.

Display vector data as points and lines. Mapping Toolbox vector map display of line objects works much like MATLAB line display functions. Mapping Toolbox supports versions of many MATLAB

Create a map of the standard version of the Lambert Conformal Conic projection into the Southern Hemisphere. The example overrides the default standard parallels and sets the MapLatLimit

Composite and animate data from multiple Web Map Service (WMS) layers.

We'd like to read in locations of recent earthquakes from USGS website and plot them on an interactive map.

This function returns a logical array describing the landness of any given lat/lon arrays. Requires Matlab's Mapping Toolbox.

ToR_LandSat8 has the following general form:

This function interpolates values of a georeferenced tiff file, given lat/lon coordinates or map x/y locations corresponding to the map projection associated with the tiff file. This

In this example, I will load an some historical data, earthquake hypocenters from the ISC-GEM Catalogue and see how we can work when the amount of data may be too large to fit into memory all at

QUIVERMC is an adapted version of Andrew Roberts' ncquiverref. This function fixes a couple of problems with Matlab's quiverm function. The two primary issues with quiverm are as follows:

This function reads a sub region of a geotiff or geojp2 image.

The scalebar function places a graphical reference scale on a map. This function was designed as a simpler alternative to the built-in scaleruler function.

Author: Matthew J. Simoneau

The gravity_data function returns gridded Antarctic gravity anomaly data from Scheinert et al., 2016. See the Data Citation section below for information about this dataset.

The smithlakes function plots 124 ICESat-detected active subglacial Antarctic lakes identified in a paper by Smith et al. For details of the underlying data, read the Smith paper and data

This function returns the 1993-2014 linear sea level trend for a given lat/lon, in millimeters per year. Data from CU Boulder Sea Level Research group. Data of lower spatial resolution (1

This function plots the grounding line or hydrostatic line identified by the Antarctic Surface Accumulation and Ice Discharge (ASAID) project.

Icesat plots the grounding zone inferred by ICESat. Data details can be found here. This command has a rather general name for a rather specific function because it may be updated at a future

This function Antarctic Circumpolar Current Fronts as identified by Orsi, A. H., T. Whitworth III and W. D. Nowlin, Jr., 1995: On the meridional extent and fronts of the Antarctic

The fastscatterm function places color-scaled point markers on map coordinates. This is a much faster version of the Mapping Toolbox's scatterm function, adapted from Aslak Grinsted's

The gravity_interp function interpolates Antarctic gravity anomalies to arbitary southern- hemisphere coordinates. Data are from Scheinert et al. 2016 and are described below. If you

This function creates color-scaled text labels on maps.

The reftrack function returns coordinates of ICESat's 91-day orbit reference tracks.

By Will Campbell

The circlem draws circles on maps.

The pathdist function uses the distance function to calculate cumulative distance traveled along a path given by the arrays lat and lon. (Requires Mapping Toolbox). Always assumes WGS84

This function plots a subregion or continent-wide image of the center-filled 240 m resolution Landsat Image Mosaic of Antarctica. The mosaic is comprised of Landsat 7 images taken primarly

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:

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

Contact your local office