Create Signals with MATLAB Expressions and Variables - MATLAB & Simulink (original) (raw)

Main Content

The Signal Editor allows you to add signals using MATLAB® expressions and variables using the Author and Insert dialog box. In the Insert section, select Author Signal.

Author and Insert dialog box with default Time and Data fields

For a description of these parameters, see Author Signal.

When you click Insert Signal, the interface evaluates the signal, updates the signal information in the dialog box, and adds the signal to theInputs pane. In addition, the number of samples, signal data type, and signal dimension also appear.

To see example Time and Data entries, clickShow Examples. To experiment with the signals from these example signal notations, click Apply Example for the associated example. You can also modify the examples before inserting.

For example, to create a sine wave, click Apply Example next to theCreate a Sine Wave example and click Insert Signal. Observe that dialog box displays the number of samples, signal data type, and signal dimensions.

Author and Insert dialog box with Time set to linspace(0,10,101), Data set to sin([0:0.1:10]'), and Data type set to double

To view the signal, cancel the Author and Insert dialog box, navigate to theInputs pane, and double-click hide/show for the new signal. If a signal has real and imaginary parts, both parts display in one plot. The tabular data editor also reflects the signal data.

Plot of the sine wave and its time and data

Explore the plots using the plot context menus Align and Zoom & Pan.

If the data does not plot as expected, click Fit to view in theZoom & Pan section. For multidimensional signals, also make sure that you have the right plot selected for the column data you are editing.

Tip

To produce signals with linearly spaced values for time, use the linspace function, for example:

Plot of time=linspace(0,10,101) with data=[0:0.1:10]

To edit signal data without using MATLAB expressions, see Work with Basic Signal Data.

Replace Signal Data with MATLAB Expressions

You can replace signal data using MATLAB expressions at any time, regardless of how you created the original signal data. To replace signal data, select that signal in the Scenarios and Signals section, and then click the replace button (). Use the Author and Replace Signal Data dialog box as if you were inserting a new expression with the Author and Insert dialog box. For more information, see Create Signals with MATLAB Expressions and Variables.

Note

You cannot change data types to or from a fixed-point data type.

Tip

When replacing a signal, the signal dimension and complexity of the new signal must be the same as the signal being replaced.

Tip

To produce signals with linearly spaced values for time, use the linspace function, for example:

See Also

Blocks

Tools

Topics