Main Content

trajectory

Create trajectory from GPS data object

Since R2024b

Description

gpsTrajectory = trajectory(gpsData) creates a trajectory, gpsTrajectory, from the input GPSData object gpsData.

example

gpsTrajectory = trajectory(gpsData,Timestamps=timestamps) creates a trajectory from the specified timestamps timestamps of the input GPS data.

gpsTrajectory = trajectory(gpsData,RowIndices=rowIndices) creates a trajectory from the specified row indices rowIndices of the input GPS data.

gpsTrajectory = trajectory(___,Name=Value) specifies options using name-value arguments in addition to any combination of input arguments from the previous syntaxes. For example, TimeOrigin=2 subtracts 2 seconds from the timestamps in the specified GPS data when creating the trajectory.

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.

Examples

collapse all

Load recorded GPS data into the workspace.

load("recordedGPSData.mat")

Initialize a GPSData object using information from the loaded GPS data.

gpsData = scenariobuilder.GPSData(timestamps,latitudes,longitudes,altitudes)
gpsData = 
  GPSData with properties:

          Name: ''

    NumSamples: 392
      Duration: 19.5498
    SampleRate: 20.0513
    SampleTime: 0.0500
    Timestamps: [392×1 double]

      Latitude: [392×1 single]
     Longitude: [392×1 single]
      Altitude: [392×1 single]

    Attributes: []

Create a trajectory from the GPS data object.

gpsTrajectory = trajectory(gpsData)
gpsTrajectory = 
  Trajectory with properties:

               Name: ''

         NumSamples: 392
           Duration: 19.5498
         SampleRate: 20.0513
         SampleTime: 0.0500
         Timestamps: [392×1 double]

           Position: [392×3 double]
        Orientation: [392×3 double]
           Velocity: [392×3 double]
             Course: [392×1 double]
        GroundSpeed: [392×1 double]
       Acceleration: [392×3 double]
    AngularVelocity: [392×3 double]

        LocalOrigin: [45.5278 -122.6556 0]
         TimeOrigin: 1.4616e+09

         Attributes: []

Plot the trajectory created from the GPS data.

plot(gpsTrajectory)

Input Arguments

collapse all

GPS data, specified as a GPSData object.

Row indices of the GPS data for which to create a trajectory, specified as a scalar or an N-element vector of positive integers. N is the number of rows of the gpsData input from which to create a trajectory. Values must be in the range [1, NumSamples], where NumSamples is the number of samples in the input GPS data object gpsData.

Data Types: single | double | uint8 | uint16 | uint32 | uint64

Timestamps of GPS data for which to create trajectory, specified as an N-element vector, an N-element datetime array, or an N-element duration array. N is the number of timestamps. The data type of the timestamps value and the data type of the Timestamps property of the input GPS data object gpsData must be the same. If you specify an N-element numeric column vector, units must be in seconds.

Data Types: single | double

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: trajectory = trajectory(gpsData,TimeReference=2) subtracts 2 seconds from the timestamps in the GPS data when creating the trajectory trajectory.

Reference time to subtract from all timestamps, specified as a nonnegative scalar, a datetime scalar, or a duration scalar. The data type of the TimeOrigin value and the data type of the Timestamps property of the input GPS data object gpsData must be the same. If you specify a nonnegative scalar, units must be in seconds.

The value of the TimeOrigin argument must be smaller than the first value of the Timestamps property in the input GPS data object gpsData. By default, the TimeOrigin value is the timestamp of first sample in the input GPS data object gpsData.

Data Types: single | double

Anchor of local geographic coordinates, specified as a three-element row vector in the form [latitude longitude altitude]. Units of latitude and longitude are in degrees, and units of longitude are in meters. By default, the LocalOrigin value is the geographic coordinates of first sample in the input GPS data object gpsData.

Note

When you specify the LocalOrigin name-value argument, the function uses the specified reference coordinates to convert geographic coordinates to local coordinates. For more information, see the latlon2local function.

Data Types: single | double

Output Arguments

collapse all

Trajectory from the GPS data, returned as a Trajectory object.

Version History

Introduced in R2024b