Main Content

writeCSV

Write trajectory data into CSV file

Since R2024b

Description

writeCSV(trajectory) writes the trajectory data to a CSV file in the current working directory. The CSV file contains these columns:

  • time — Timestamps of trajectory waypoints.

  • xx-coordinates of waypoints. Units are in meters.

  • yy-coordinates of waypoints. Units are in meters.

  • zz-coordinates of waypoints. Units are in meters.

example

filename = writeCSV(trajectory) writes the trajectory data to a CSV file in the current working directory, and returns the saved filename filename.

writeCSV(trajectory,Name=Value) specifies options using one or more name-value arguments. For example, FileName="Vehicle.csv" writes the trajectory data to the Vehicle.csv file in the current working directory.

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 GPS trajectory data into the workspace.

load("recordedGPSData.mat","X","Y","Z","timestamps")

Create a trajectory object by using the loaded timestamps and xyz-coordinates.

traj = scenariobuilder.Trajectory(timestamps,X,Y,Z)
traj = 
  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: [0 0 0]
         TimeOrigin: 0

         Attributes: []

Write the trajectory to a CSV file. By default, the writeCSV function creates a Vehicle.csv file in the current working directory and writes the trajectory to it.

writeCSV(traj);

Specify a filename to write trajectory to it.

filename = "Trajectory.csv";

Write the trajectory to the specified CSV file. The writeCSV function creates a Trajectory.csv file in the current working directory and writes the trajectory to it.

writeCSV(traj,FileName=filename)
ans = 
"Trajectory.csv"

Input Arguments

collapse all

Trajectory with timestamps and waypoints, specified as a Trajectory object.

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: writeCSV(trajectory,FileName="Vehicle.csv") writes the trajectory data to the Vehicle.csv file in the current working directory.

Filename to which to save the trajectory data, specified as a character vector or string scalar. For an existing file with filename FileName, the function appends an incremental numeric integer at the end of the filename. For example, if the file Vehicle.csv already exists, the function creates the file Vehicle1.csv instead.

Data Types: char | string

Export the orientation to the CSV file, specified as a logical 1 (true) or 0 (false).

If specified as true, the function adds these columns to the CSV file:

  • roll — Roll angle of the waypoints. Units are in degrees.

  • pitch — Pitch angle of the waypoints. Units are in degrees.

  • yaw — Yaw angle of the waypoints. Units are in degrees.

Data Types: logical

Output Arguments

collapse all

Name of the saved CSV file, returned as a string scalar or character vector.

Data Types: char | string

Version History

Introduced in R2024b