Automatically update charted data
Use data linking to synchronize charts and their workspace variables. Linked charts automatically update with changes to workspace variables, and workspace variables automatically update with chart modifications made via the brush tool.
Link charts and workspace variables using the linkdata
function or by
selecting from the figure toolbar.
linkdata on
turns on data linking mode for the current
axes.
linkdata off
turns off data linking mode.
linkdata
toggles the data linking mode between
'on'
and 'off'
.
linkdata showdialog
opens the Linked Plot Data
Sources dialog box. Use this syntax to interactively synchronize a chart
with workspace variables.
linkdata(
specifies
the data linking mode for the specified figure. Use single or double quotation marks
around the options fig
,___)'on'
and 'off'
. For example,
linkdata(fig,'on')
.
l = linkdata
creates a LinkData
object. This
syntax is useful for querying the data linking mode.
l = linkdata(
creates a
fig
)LinkData
object for the specified figure.
If linkdata
cannot unambiguously identify data sources for a
chart, then the chart will not synchronize with workspace variables. If you call
linkdata
and your chart does not update when you change a variable,
then open the Linked Plot Data Sources dialog box by calling
linkdata showdialog
and manually link the chart to its data
sources.
The linkdata
function updates linked data sources and charts
around twice a second. To smoothly animate changes in data values, create loops that
execute two times per second or less. For more information, see the pause
function.
Once a chart is synchronized with its workspace variables, programmatic changes to the
data properties of the chart (for example, XData
) do not update the
workspace variables. Workspace variables only update when you modify plotted data
interactively, using the brush tool.
Data linking connects a chart and its workspace variables using the chart's data source
properties (for example, XDataSource
). When you turn on data linking for a
figure, MATLAB® compares variables in the workspace to plotted data in the figure. When it finds
a match, MATLAB assigns that variable to the appropriate data source property of the chart.