Refresh data in graph when data source is specified
refreshdata evaluates any data source properties (XDataSource, YDataSource, or ZDataSource) on all objects in graphs in the current figure. If the specified data source has changed, the MATLAB® software updates the graph to reflect this change.
Note: The variable assigned to the data source property must be in the base workspace or you must specify the workspace option as 'caller'.
refreshdata(object_handles,'workspace') enables you to specify whether the data source properties are evaluated in the base workspace or the workspace of the function in which refreshdata was called. workspace is a string that can be
base — Evaluate the data source properties in the base workspace.
caller — Evaluate the data source properties in the workspace of the function that called refreshdata.
Plot a sine wave and return the chart line handle, h.
x = linspace(0,8); y = sin(x); figure h = plot(x,y);
Identify the data sources for the plot by setting the XDataSource and YDataSource properties of the line to x and y, respectively. Then, modify y. Call refreshdata so that the graph updates with the changes to y.
h.XDataSource = 'x'; h.YDataSource = 'y'; y = sin(x.^3); refreshdata
The Linked Plots feature (see documentation for linkdata) sets up data sources for graphs and synchronizes them with the workspace variables they display. When you use this feature, you do not also need to call refreshdata, as it is essentially automatically triggered every time a data source changes.
If you are not using the Linked Plots feature, you need to set the XDataSource, YDataSource, and/or ZDataSource properties of a graph in order to use refreshdata. You can do that programmatically, as shown in the examples below, or use the Property Editor, one of the plotting tools. In the Property Editor, select the graph (e.g., a lineseries object) and type in (or select from the drop-down choices) the name(s) of the workspace variable(s) from which you want the plot to refresh, in the fields labelled X Data Source, Y Data Source, and/or Z Data Source. The call to refreshdata causes the graph to update.