Show grid values in a figure



show(map) displays the occupancy grid map in the current axes, with the axes labels representing the world coordinates.

show(map,'local') displays the occupancy grid map in the current axes, with the axes labels representing the local coordinates instead of world coordinates.

show(map,'grid') displays the occupancy grid map in the current axes, with the axes labels representing the grid coordinates.

show(___,Name,Value) specifies additional options specified by one or more name-value pair arguments.

mapImage = show(___) returns the handle to the image object created by show.


collapse all

Create a 10 m-by-10 m empty map.

map = occupancyMap(10,10,10);

Update the occupancy of world locations with specific probability values and display the map.

x = [1.2; 2.3; 3.4; 4.5; 5.6];
y = [5.0; 4.0; 3.0; 2.0; 1.0];

pvalues = [0.2 0.4 0.6 0.8 1];

updateOccupancy(map,[x y],pvalues)

Inflate occupied areas by a radius of 0.5 m. Larger occupancy values overwrite the smaller values.


Get grid locations from world locations.

ij = world2grid(map,[x y]);

Set grid locations to occupied locations.


Convert a portable graymap (PGM) file containing a ROS map into an occupancyMap for use in MATLAB.

Import the image using imread. Crop the image to the playpen area.

image = imread('playpen_map.pgm');
imageCropped = image(750:1250,750:1250);

PGM values are expressed from 0 to 255 as uint8. Normalize these values by converting the cropped image to double and dividing each cell by 255. This image shows obstacles as values close to 0. Subtract the normalized image from 1 to get occupancy values with 1 representing occupied space.

imageNorm = double(imageCropped)/255;
imageOccupancy = 1 - imageNorm;

Create the occupancyMap object using an adjusted map image. The imported map resolution is 20 cells per meter.

map = occupancyMap(imageOccupancy,20);

Input Arguments

collapse all

Map representation, specified as a occupancyMap object. This object represents the environment of the vehicle. The object contains a matrix grid with values representing the probability of the occupancy of that cell. Values close to 1 represent a high probability that the cell contains an obstacle. Values close to 0 represent a high probability that the cell is not occupied and obstacle free.

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: 'Parent',axHandle

Axes to plot the map specified as either an Axes or UIAxes object. See axes or uiaxes.

Update existing map plot, specified as 0 or 1. If you previously plotted your map on your figure, set to 1 for a faster update to the figure. This is useful for updating the figure in a loop for fast animations.


collapse all

Map image, specified as an object handle.

Introduced in R2019b