animatedline

Creates a line that grows as points are added to it.

Category: Graphics > 2-D and 3-D Plots

Syntax

h = animatedline

Creates an empty animated line in the current axes.

h = animatedline(x, y)

Creates the line with initial points.

h = animatedline(___, Name, Value)

Sets line properties such as 'Color', 'LineWidth' or 'MaximumNumPoints'.

Description

An animated line is meant for data that arrives step by step, such as a simulation or a measurement loop. Each addpoints call appends to the line instead of redrawing a full plot, and drawnow makes the update visible during a loop.

Input arguments

x, y
Vectors of initial coordinates.
'MaximumNumPoints'
Largest number of points kept; older points are dropped first.

Output arguments

h
An AnimatedLine handle. Add points with addpoints, read them with getpoints and empty it with clearpoints.

Example

Grow a line in a loop

h = animatedline('LineWidth', 2);
for k = 1:20
    addpoints(h, k, sin(k/3));
    drawnow
end
[x, y] = getpoints(h);
disp(numel(x))
disp(round(y(1:3), 4))
Output
    20
    0.3272    0.6184    0.8415

See also

addpoints clearpoints getpoints drawnow plot