Main Content

Generate Waveform

Generate waveform in Live Editor

Since R2025a

Description

The Generate Waveform task lets you create common waveforms. The task automatically generates MATLAB® code for your live script.

Using this task, you can interactively create data from common waveforms using vectors, timeseries, timetables, and data arrays. For general information about Live Editor tasks, see Add Interactive Tasks to a Live Script.

By default, the live task creates a workspace variable, generatedWaveform.

Generate Waveform task in Live Editor

Open the Task

To add the Generate Waveform task to a live script in the MATLAB Editor:

  • On the Live Editor tab, select Task > Generate Waveform.

  • In a code block in the script, type a relevant keyword, such as generate waveform, vector, timeseries, timetable, input, signal, source, or waveform. From the selected completions, select Generate Waveform.

Choosing Generate Waveform from command completion suggestions

Examples

expand all

This example shows how to use the Generate Waveform Live Editor task to create numerical data for an inport port by generating a Sine wave. By default, Generate Waveform creates a variable named generatedWaveform in the workspace with a numerical signal type and outputs data in the timeseries format. In the

Select waveform section, select Sine.

Set input parameters section, set Amplitude to 10.

Set output format section, set the format to Timeseries.

Display results section, click Plot.

To the upper right, a plot of the waveform displays.

Sine wave plot with amplitude of 10

To see the code that this task generates, expand the task display by clicking Show code button at the bottom of the task parameter area.

Generated code for Sine wave plot with amplitude of 10

To interactively control waveform parameters, such as the amplitude of the waveform, add a slider to the top of the script. Place the mouse at the top of the live script. In the toolstrip, select Control > Slider. Configure the slider control for the Amplitude parameter.

Slider for Generate Waveform task

You can use the generatedWaveform timeseries object data in many of the cases where you want to input data, for example, to import to Root Inport Mapper or to work with source blocks. To save this task, save the live script.

This example shows how to use the Generate Waveform Live Editor task to create numerical data for an inport port in a model by generating a Cosine waveform. By default, Generate Waveform creates a variable named generatedWaveform in the workspace with a numerical signal type and outputs data in the timeseries format.

Select waveform section, select Cosine.

Set input parameters section, set Amplitude to 10.

Set output format section, set the format to Timeseries.

Display results section, click Plot.

To the upper right, a plot of the waveform displays.

Cosine wave plot with amplitude of 10

You can use the generatedWaveform timeseries object data in many of the cases where you want to input data, for example, to import to Root Inport Mapper or to work with source blocks. To save this task, save the live script.

At the bottom of the live task, add the code to open the CreateSignalInport model, set the generatedWaveform variable to the input, load the input from the workspace, and simulate the model.

Code for setting generatedWaveform variable to input

In the live task, click Run.

In the model, open the Scope block.

Related Examples

Parameters

expand all

Type of data to create, specified as Sine, Cosine, Square, Step, Pulse, Gaussian Noise, Constant, Ramp, Sawtooth, or Triangle.

Waveform creation parameters. You can set the Start time(s), End time(s), and Sample time(s) settings for each waveform type. The appearance of the other parameters depends on the waveform type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Data type of the created data, specified as Timeseries, Data array, Timeseries, and Timetable.

Set up the properties for your data. The data properties depend on the Select type of signal and Select output format settings. Depending on these settings, you can set properties such as:

  • Vector type

  • Data type

  • Variable name

  • Time unit

To plot the data, select the Plot check box. The plot displays to the right.

Version History

Introduced in R2025a

See Also

Live Editor Tasks

Blocks