Instead of making a high level plot call, consider setting the properties of the descriptor, namely XData and YData , in a loop:
figure(1); lHandle = line(nan, nan); %# Generate a blank line and return the line handle for i = 1:1000 X = get(lHandle, 'XData'); Y = get(lHandle, 'YData'); X = [X i]; Y = [Y i]; set(lHandle, 'XData', X, 'YData', Y); end
Performing this, a tic / toc before / after the code gives 0.09 seconds; naive plot , as you, as you saw, gives a runtime of almost 20 seconds.
Note that in this example, I used get to generate a dataset; I assume that for a real-time plot, you have some DatasetX and DatasetY to plot, so you will need to work with your data. But in the end, as soon as you have the data set that you want to build at a specific time, just set the entire string to XData and YData .
Finally, note that this set call becomes a bit cumbersome for very large datasets, since we must set the line data each time, not add to it. (But this is certainly even faster than using plot .) This can be quite good, depending on how often your dataset changes. See this question for more details.
EDIT . With MATLAB R2014b, an animinatedline object simplifies the mapping of points from streaming data:
Animated line objects optimize line animation by accumulating data from a stream data source. After you create an initial animated line using the animated line function, you can add new points to the line without overriding existing points. Change the appearance of the animated string by setting its properties.