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, identify data sources, and then modify its YDataSource:
x = 0:.1:8; y = sin(x); h = plot(x,y) set(h,'YDataSource','y') set(h,'XDataSource','x') y = sin(x.^3); refreshdata
Create a surface plot, identify a ZDataSource for it, and change the data to a different size.
Z = peaks(5); h = surf(Z) set(h,'ZDataSource','Z') pause(3) Z = peaks(25); 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.