Main Content

Create Signals with MATLAB Expressions and Variables

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 the Inputs pane. In addition, the number of samples, signal data type, and signal dimension also appear.

To see example Time and Data entries, click Show 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 the Create 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 the Inputs 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 the Zoom & Pan section. For multidimensional signals, also make sure that you have the right plot selected for the column data you are editing.

  • In the Measure section, click Data Cursors to display one or two cursors for the plot. These cursors display the T and Y values of a data point in the plot. To view a data point, click a point on the plot line.

  • In the Zoom & Pan section, select how you want to zoom and pan the signal plots. Zooming is only for the selected axis.

    Type of Zoom or PanButton to Click

    Zoom in along the T- and Y-axes.

    Zoom t and y icon

    Zoom in along the time axis. After selecting the icon, on the graph, drag the mouse to select an area to enlarge.

    Zoom time axis icon

    Zoom in along the data value axis. After selecting the icon, on the graph, drag the mouse to select an area to enlarge.

    Zoom data value axis icon

    Zoom out from the graph.

    Zoom out icon

    Fit the plot to the graph. After selecting the icon, click the graph to enlarge the plot to fill the graph.

    Fit to plot icon

    Pan the graph up, down, left, or right. Select the icon. On the graph, hold the left mouse button and move the mouse to the area of the graph that you want to view.

    Pan icon

Tip

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

  • Timelinspace(0,10,101)

  • Data[0:0.1:10]

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:

  • Timelinspace(0,10,11)

  • Data[0:10]

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

See Also

Blocks

Tools

Related Topics