Main Content

egoLaneIndex

Calculate ego travel lane indices from lane boundary detections

Since R2025a

Description

[egoLaneIndices,numLanes] = egoLaneIndex(lanedata) returns the index of the lane in which the ego is traveling, egoLaneIndices for each timestamp in the input recorded lane boundary data lanedata. The function also returns the total number of lanes numLanes detected at each timestamp.

example

[egoLaneIndices,numLanes] = egoLaneIndex(lanedata,rowIndices) returns the ego travel lane indices for the specified row indices rowIndices.

Note

This function requires the Scenario Builder for Automated Driving Toolbox™ support package. You can install the Scenario Builder for Automated Driving Toolbox support package from the Add-On Explorer. For more information about installing add-ons, see Get and Manage Add-Ons.

example

Examples

collapse all

Load recorded lane boundary data into the workspace.

data = load("egoLaneIndexData.mat");
laneDets = data.laneDetections;

Calculate the ego travel lane index and the number of lanes for each timestamp of the loaded lane boundary data.

[egoLaneIdx,numLanes] = egoLaneIndex(laneDets);

Display the lane indices in which the ego is traveling for first few timestamps.

head(egoLaneIdx)
     2
     2
     2
     2
     2
     2
     2
     2

Display the total number of lanes detected at the first few timestamps.

head(numLanes)
     3
     3
     3
     3
     3
     3
     3
     3

Specify a few indices of lane detection frames, which correspond to timestamps of the loaded lane boundary data.

frameIdx = 15:20;

Calculate the ego travel lane index and the number of lanes for the specified frames of the loaded lane boundary data.

[egoLaneIdx,numLanes] = egoLaneIndex(laneDets,frameIdx);

Display the lane indices in which the ego is traveling for the specified frames.

head(egoLaneIdx)
     2
     2
     2
     2
     2
     2

Display the total number of lanes detected for the specified frames.

head(numLanes)
     3
     3
     3
     3
     3
     3

Input Arguments

collapse all

Recorded lane boundary data, specified as a laneData object.

Row indices for which to detect lane indices, specified as an N-element row vector of positive integers. N is the number of rows of the laneData input for which to extract the ego travel lane indices. Values must be in the range [1, NumSamples], where NumSamples is the value of the NumSamples property of the input laneData object lanedata.

Data Types: double

Output Arguments

collapse all

Indices of the lanes in which the ego is traveling, returned as an N-element row vector of positive integers. N is the number of extracted ego travel lane indices. Each lane index corresponds to a timestamp in the Timestamps property of the input laneData object lanedata.

If you specify the first syntax, egoLaneIndices contains lane indices for all timestamps in the input laneData object lanedata.

The function calculates the lane indices in left-to-right order, with respect to the travel direction of the ego vehicle, and excludes the shoulder lanes.

Data Types: double

Number of lanes detected at each timestamp, returned as an N-element row vector of positive integers. N is the number of extracted ego travel lane indices.

If you specify the first syntax, numLanes contains the number of detected lanes for all timestamps in the input laneData object lanedata.

Data Types: double

Version History

Introduced in R2025a