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

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

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.

The following document was built from posts written for the blog "Loren on the Art of MATLAB". The ideas presented below in anonymous functions have been written as .m files so that they might

The disthist function creates a histogram of distances between geolocated waypoints assuming a great circle path along the WGS84 ellipsoid.

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

Create a range of different maps using mapshow.

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

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

There are many geospatial data sets that contain data with coordinates in latitude and longitude in units of degrees. This example illustrates how to import geographic data with

Create a range of different maps using geoshow .

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

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 assocaited with th 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 docid:map_ref.f12-569586 function to generate a buffer zone internal to a land area polygon. For more information about this topic, see docid:map_ug.f7-6413 .

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 docid:map_ref.f15-424086 function. The example uses patch data for Indiana from the usastatehi shapefile. For more information, see

Overlay polygons using set logic. The docid:map_ref.bve9g51-1 function can perform standard set operations, such as intersection, union, subtraction, and exclusive OR, on two sets of

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 docid:map_ref.f14-376605 function. Simplifying polygon and line data can speed up certain calculations without making any noticeable impact on

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

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

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

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

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

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:

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

Add graphic scales to maps and how to modify the display properties of graphic scales.

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.

The north arrow element provides the orientation of a map by pointing to the geographic North Pole. You can use the northarrow function to display a symbol indicating the direction due north

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

Inset maps are often used to display widely separated areas, generally at the same scale, or to place a map in context by including overviews at smaller scales. You can create inset maps by

Set up map axes.

Use surflsrm to display surface illumination over colored elevation data.

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.

Create cylindrical projection using map limit properties.

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

Author: Matthew J. Simoneau

How to:

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

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

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.

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

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

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

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

Antmap is part of Antarctic Mapping Tools for Matlab (Greene et al., 2017). Click here for a complete list of functions in AMT.

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

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

Mapzoom is part of Antarctic Mapping Tools for Matlab (Greene et al., 2017). Click here for a complete list of functions in AMT.

ToR_LandSat8 has the following general form:

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

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 scalebar function places a graphical reference scale on a map. This function was designed as a simpler alternative to the built-in scaleruler function.

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

The pathdist function uses the distance function to calculate cumulative distance traveled along a path given by the arrays lat and lon. This may be useful when variables such as ice

The circlem draws circles on maps.

This function creates color-scaled text labels on maps.

Scarlabel and corelabel are part of Antarctic Mapping Tools for Matlab (Greene et al., 2017). Click here for a complete list of functions in AMT.

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

This function employs the interpm function to densifiy lat/lon sampling in lines or polygons, but extends the available input units to include 'meters' or 'kilometers'. However, note that

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

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

Scalebar is part of Antarctic Mapping Tools for Matlab (Greene et al., 2017). Click here for a complete list of functions in AMT.

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

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

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

Choose your country 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 location from the following list:

See all countries