Create road lane marking object


lm = laneMarking(type) creates a default lane marking object of the specified type (solid lane, dashed lane, and so on). This object defines the characteristics of a lane boundary marking on a road. When creating roads in a driving scenario, you can use lane marking objects as inputs to the lanespec object. For more details, see Lane Specifications.


lm = laneMarking(type,Name,Value) set the properties of the lane marking object using one or more name-value pairs. For example, laneMarking('Solid','Color','yellow') creates a solid yellow lane marking.


collapse all

Create a driving scenario and the road centers for a straight, 80-meter road.

scenario = drivingScenario;
roadCenters = [0 0; 80 0];

Create a lanespec object for a four-lane road. Use the laneMarking function to specify its five lane markings. The center line is double-solid and double yellow. The outermost lines are solid and white. The inner lines are dashed and white.

solidW = laneMarking('Solid','Width',0.3);
dashW = laneMarking('Dashed','Space',5);
doubleY = laneMarking('DoubleSolid','Color','yellow');
lspec = lanespec([2 2],'Width',[5 5 5 5], ...
    'Marking',[solidW dashW doubleY dashW solidW]);

Add the road to the driving scenario. Display the road.


Simulate a driving scenario with one car traveling on an S-curve. Create and plot the lane boundaries.

Create the driving scenario with one road having an S-curve.

scenario = drivingScenario('StopTime',3);
roadcenters = [-35 20 0; -20 -20 0; 0 0 0; 20 20 0; 35 -20 0];

Create the lanes and add them to the road.

lm = [laneMarking('Solid','Color','w'); ...
    laneMarking('Dashed','Color','y'); ...
    laneMarking('Dashed','Color','y'); ...
ls = lanespec(3,'Marking',lm);

Add an ego vehicle and specify its trajectory from its speed and waypoints. The car travels at 30 meters per second.

car = vehicle(scenario, ...
    'ClassID',1, ...
    'Position',[-35 20 0]);
waypoints = [-35 20 0; -20 -20 0; 0 0 0; 20 20 0; 35 -20 0];
speed = 30;

Plot the scenario and corresponding chase plot.



Run the simulation loop.

  1. Initialize a bird's-eye plot and create an outline plotter, left-lane and right-lane boundary plotters, and a road boundary plotter.

  2. Obtain the road boundaries and rectangular outlines.

  3. Obtain the lane boundaries to the left and right of the vehicle.

  4. Advance the simulation and update the plotters.

bep = birdsEyePlot('XLim',[-40 40],'YLim',[-30 30]);
olPlotter = outlinePlotter(bep);
lblPlotter = laneBoundaryPlotter(bep,'Color','r','LineStyle','-');
lbrPlotter = laneBoundaryPlotter(bep,'Color','g','LineStyle','-');
rbsEdgePlotter = laneBoundaryPlotter(bep);
while advance(scenario)
    rbs = roadBoundaries(car);
    [position,yaw,length,width,originOffset,color] = targetOutlines(car);
    lb = laneBoundaries(car,'XDistance',0:5:30,'LocationType','Center', ...
    plotOutline(olPlotter,position,yaw,length,width, ...

Input Arguments

collapse all

Type of lane marking, specified as one of these values.

'Unmarked' 'Solid''Dashed''DoubleSolid''DoubleDashed''SolidDashed''DashedSolid'

No lane marking

Solid line

Dashed line

Two solid lines

Two dashed lines

Solid line on left, dashed line on right

Dashed line on left, solid line on right

The type of lane marking is stored in Type, a read-only property of the returned lane marking object.

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: laneMarking('Dashed','Width',0.25,'Length',5.0) creates a lane with dashes that are 0.25 meters wide and spaced 5 meters apart.

Lane marking widths, specified as the comma-separated pair consisting of 'Width' and a positive real scalar. For a double lane marker, the same width is used for both lines. Units are in meters.

Example: 0.20

Color of lane marking, specified as the comma-separated pair consisting of 'Color' and a color name or RGB triplet. For a double lane marker, the same color is used for both lines.

For a custom color, specify an RGB triplet. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range [0, 1]; for example, [0.4 0.6 0.7]. Alternatively, you can specify some common colors by name. This table lists the named color options and the equivalent RGB triplet values.

Color NameRGB TripletAppearance
'red'[1 0 0]

'green'[0 1 0]

'blue'[0 0 1]

'cyan' [0 1 1]

'magenta'[1 0 1]

'yellow'[0.98 0.86 0.36]

'black'[0 0 0]

'white'[1 1 1]

Example: [0.8 0.8 0.8]

Saturation strength of lane marking color, specified as the comma-separated pair consisting of 'Strength' and a real scalar in the range [0, 1]. A value of 0 corresponds to a marking whose color is fully unsaturated. The marking is gray. A value of 1 corresponds to a marking whose color is fully saturated. For a double lane marking, the same strength is used for both lines.

Example: 0.20

Length of dash in dashed lines, specified as the comma-separated pair consisting of 'Length' and a positive real scalar. For a double lane marking, the same length is used for both lines. The dash is the visible part of a dashed line. Units are in meters.

Example: 2.0

Length of space between the end of one dash and the beginning of the next dash, specified as the comma-separated pair consisting of 'Space' and a positive real scalar. For a double lane marking, the same length is used for both lines. Units are in meters.

Example: 2.0

Output Arguments

collapse all

Lane marking, returned as a LaneMarking object, SolidMarking object, or DashedMarking object. The type of returned object depends on the type of input lane marking specified for the type input.

Input TypeOutput Lane MarkingLane Marking Properties

LaneMarking object

  • Type


SolidMarking object

  • Color

  • Width

  • Strength

  • Type


DashedMarking object

  • Length

  • Space

  • Color

  • Width

  • Strength

  • Type


You can set these properties when you create the lane marking object by using the corresponding name-value pairs of the laneMarking function. To update these properties after creation, use dot notation. For example:

lm = laneMarking('Solid');
lm.Width = 0.2;
You can set all properties after creation except Type, which is read-only.

More About

collapse all

Lane Specifications

The diagram shows the components and geometric properties of roads, lanes, and lane markings.

Left and right are defined with respect to the road centers. Specify the road centers as a matrix input to the road function. The road centers create a directed line, starting from the first row to the last row of the matrix. Left and right mean left and right of the directed line. The width of the road is the sum of all lane widths plus half the widths of the left-edge and right-edge boundary markings.

The lane specification object, lanespec, defines the road lanes.

  • The NumLanes property specifies the number of lanes. You must specify the number of lanes when you create this object.

  • The Width property specifies the width of each lane.

  • The Marking property contains the specifications of each lane marking in the road. Marking is an array of lane marking objects, with one object per lane. To create these objects, use the laneMarking function. Lane marking specifications include:

    • Type — Type of lane marking (solid, dashed, and so on)

    • Width — Lane marking width

    • Color — Lane marking color

    • Length — For dashed lanes, the length of each dashed line

    • Spacing — For dashed lanes, the spacing between dashes

  • The Type property contains the lane type specifications of each lane in the road. Type can be a homogeneous lane type object or heterogeneous lane type array.

    • Homogeneous lane type object contain lane type specifications of all the lanes in the road.

    • Heterogeneous lane type array contain an array of lane type objects, with one object per lane.

    To create these objects, use the laneType function. Lane type specifications include:

    • Type — Type of lane (driving, border, and so on)

    • Color — Lane color

    • Strength — Strength of the lane color

Introduced in R2018a