Main Content

crop

Crop data from sensor data object

Since R2024b

Description

crop(sensorDataObj,startTime,endTime) crops data from the sensor data object to the time interval from the specified start time startTime to the specified end time endTime, and updates the sensor data object sensorDataObj.

example

sensorDataCropped = crop(sensorDataObj,startTime,endTime) crops data from the input sensor data object sensorDataObj to the time interval from the specified start time startTime to the specified end time endTime, and returns a new cropped sensor data object sensorDataCropped. This syntax does not update the input sensor data object sensorDataObj.

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 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: []

Specify a start time and end time to which to crop data.

startTime = gpsData.Timestamps(100);
endTime = gpsData.Timestamps(200);

Crop the data of the GPS data object.

crop(gpsData,startTime,endTime)

Display the cropped GPS data.

disp(gpsData)
  GPSData with properties:

          Name: ''

    NumSamples: 101
      Duration: 5.0006
    SampleRate: 20.1975
    SampleTime: 0.0500
    Timestamps: [101×1 double]

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

    Attributes: []

Load recorded GPS 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: []

Plot the trajectory.

plot(traj)

Specify a start time and end time to which to crop data.

startTime = traj.Timestamps(100);
endTime = traj.Timestamps(200);

Crop the data of the trajectory object.

trajCropped = crop(traj,startTime,endTime)
trajCropped = 
  Trajectory with properties:

               Name: ''

         NumSamples: 101
           Duration: 5.0006
         SampleRate: 20.1975
         SampleTime: 0.0500
         Timestamps: [101×1 double]

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

        LocalOrigin: [0 0 0]
         TimeOrigin: 0

         Attributes: []

Plot the cropped trajectory.

plot(trajCropped)

Input Arguments

collapse all

Sensor data, specified as a GPSData object, Trajectory object, CameraData object, or a LidarData object.

Start time to which to crop sensor data, specified as a nonnegative scalar, a datetime scalar, or a duration scalar. The data type of the startTime value and the data type of the Timestamps property of the input sensor data object sensorDataObj must be the same. If you specify a nonnegative scalar, units must be in seconds.

The function crops the sensor data to the time interval from the specified start time startTime to the specified end time endTime.

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

End time to which to crop sensor data, specified as a positive scalar, a datetime scalar, or a duration scalar. The data type of the endTime value and the data type of the Timestamps property of the input sensor data object sensorDataObj must be the same. If you specify a positive scalar, units must be in seconds.

The function crops the sensor data to the time interval from the specified start time startTime to the specified end time endTime.

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

Output Arguments

collapse all

Cropped sensor data, returned as a GPSData object, Trajectory object, CameraData object, or a LidarData object.

Version History

Introduced in R2024b