Main Content


(Removed) Construct map graticule for surface object display

The meshgrat function has been removed. Use the geographicGrid, linspace, or ndgrid function instead. For more information, see Version History.


[lat, lon] = meshgrat(Z, R)
[lat, lon] = meshgrat(Z, R, gratsize)
[lat, lon] = meshgrat(lat, lon)
[lat, lon] = meshgrat(latlim, lonlim, gratsize)
[lat, lon] = meshgrat(lat, lon, angleunits)
[lat, lon] = meshgrat(latlim, lonlim, angleunits)
[lat, lon] = meshgrat(latlim, lonlim, gratsize, angleunits)


[lat, lon] = meshgrat(Z, R) constructs a graticule for use in displaying a regular data grid, Z. In typical usage, a latitude-longitude graticule is projected, and the grid is warped to the graticule using MATLAB® graphics functions. In this two-argument calling form, the graticule size is equal to the size of Z. 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 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/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.

[lat, lon] = meshgrat(Z, R, gratsize) produces a graticule of size gratsize. gratsize is a two-element vector of the form [number_of_parallels number_of_meridians]. If gratsize = [], then the graticule returned has the default size 50-by-100. (But if gratsize is omitted, a graticule of the same size as Z is returned.) A finer graticule uses larger arrays and takes more memory and time but produces a higher fidelity map.

[lat, lon] = meshgrat(lat, lon) takes the vectors lat and lon and returns graticule arrays of size numel(lat)-by-numel(lon). In this form, meshgrat is similar to the MATLAB function meshgrid.

[lat, lon] = meshgrat(latlim, lonlim, gratsize) returns a graticule mesh of size gratsize that covers the geographic limits defined by the two-element vectors latlim and lonlim.

[lat, lon] = meshgrat(lat, lon, angleunits), [lat, lon] = meshgrat(latlim, lonlim, angleunits), and [lat, lon] = meshgrat(latlim, lonlim, gratsize, angleunits) where angleunits can be either 'degrees' (the default) or 'radians'.

The graticule mesh is a grid of points that are projected on an axesm-based map and to which surface map objects are warped. The fineness, or resolution, of this grid determines the quality of the projection and the speed of plotting. There is no hard and fast rule for sufficient graticule resolution, but in general, cylindrical projections need very few graticules in the longitudinal direction, while complex curve-generating projections require more.


Make a (coarse) graticule for the entire world:

latlim = [-90 90]; 
lonlim = [-180 180];
[lat,lon] = meshgrat(latlim,lonlim,[3 6])
lat =

  -90.0000  -90.0000  -90.0000  -90.0000  -90.0000  -90.0000
         0         0         0         0         0         0
   90.0000   90.0000   90.0000   90.0000   90.0000   90.0000

lon =

 -180.0000 -108.0000  -36.0000   36.0000  108.0000  180.0000
 -180.0000 -108.0000  -36.0000   36.0000  108.0000  180.0000
 -180.0000 -108.0000  -36.0000   36.0000  108.0000  180.0000

These paired coordinates are the graticule vertices, which are projected according to the requirements of the desired map projection. Then data such as the elevation data in topo60c can be warped to the grid.

Version History

expand all

R2024a: Errors

Some functions that accept referencing vectors or referencing matrices as input have been removed, including the meshgrat function. Depending on the meshgrat function syntax, use the geographicGrid, linspace, or ndgrid function instead.

  • If your code uses the meshgrat function and a referencing vector or referencing matrix, replace the code by using a geographic raster reference object and the geographicGrid function. Reference objects have several advantages over referencing vectors and matrices.

    • Unlike referencing vectors and matrices, reference objects have properties that document the size of the associated raster, its geographic limits, and the direction of its rows and columns. For more information about reference object properties, see the GeographicCellsReference and GeographicPostingsReference objects.

    • You can manipulate the limits of rasters associated with reference objects using the geocrop function.

    • You can manipulate the size and resolution of rasters associated with reference objects using the georesize function.

    • Most functions that accept referencing vectors or matrices as inputs also accept reference objects.

    Create a reference object for either a raster of cells using the georefcells function or a raster of regularly posted samples using the georefpostings function. Alternatively, convert from a referencing vector or a referencing matrix to a reference object using the refvecToGeoRasterReference or refmatToGeoRasterReference function, respectively.

    Replace uses of the meshgrat function with the geographicGrid function according to these patterns.

    [lat,lon] = meshgrat(A,R);
    [lat,lon] = geographicGrid(R);
    [lat,lon] = meshgrat(A,R,gratsize);
    Rg = R;
    Rg.RasterSize = gratsize;
    [lat,lon]= geographicGrid(Rg);

  • If your code uses the meshgrat function and latitude and longitude vectors, replace the code by using the ndgrid function.

    [lat,lon] = meshgrat(lat,lon);
    [lat,lon] = ndgrid(lat,lon);

  • If your code uses the meshgrat function, latitude and longitude limits, and a graticule size, replace the code by using the linspace and ndgrid functions.

    [lat,lon] = meshgrat(latlim,lonlim,gratsize);
    latv = linspace(latlim(1),latlim(2),gratsize(1));
    lonv = linspace(lonlim(1),lonlim(2),gratsize(2));
    [lat,lon] = ndgrid(latv,lonv);