Specifying a Data Source

April 13th, 2010 Posted in Examples

Creating the

First define two variables by issuing these statements in the command window.

1
2
t = 0:.01:20;
alpha =.055;

Next t versus the expression (-alpha*t).*sin(.5*t) using the plot function or the plot tools.

1
plot(t,exp(-alpha*t).*sin(.5*t))

Varying the

Plot objects have properties that enable you to specify the source of the data that defines the object. For example, you can specify a workspace variable name or a expression as the value of the , , or ZDataSource property for a line in a plot (i.e., a lineseries object). You can then use the Property Editor to change the variable name or alter the expression, and the plot is updated to reflect the change.

After creating the graph, you can use the Property Editor to couple the plotted line to the MATLAB expression.

  • Double-click on the plotted line to display its property panel.
  • Enter the MATLAB expression exp(-alpha*t).*cos(.5*t) in the Y Data Source text field.


You can now modify the expression in the Y Data Source text field and observe how the graph changes. After changing the text, click the Refresh Data button to update the data.

In the following picture, alpha is no longer negated, so the function grows instead of decays. Also the period has been shortened by changing sin(.5*t) to sin(1.5*t).

Data Sources for Multiobject Graphs

Suppose you create a line graph from matrix data. For example,

1
2
z = peaks;
h = plot(z,'YDataSource','z');

Because there is one lineseries object for each column of z, the following is true.

The data source for h(1) is z(:,1).

The data source for h(2) is z(:,2).

1
...

The data source for h(n) is z(:,n).

Leave a Reply

You must be logged in to post a comment.