Explanation

When you call axes(h) within a loop, MATLAB makes the specified axes the current axes. However, MATLAB also attempts to give focus to the axes and its parent figure with every loop iteration, which slows performance significantly.


Suggested Action

If you are calling axes because you have multiple axes and you need to specify in which axes to plot, pass the axes handle as an argument to the plot function instead. For example, replace code such as this:

a1 = subplot(1,2,1)
a2 = subplot(1,2,2);
while 1
    axes(a1)
    plot(rand(3))
    axes(a2)
    plot(rand(3))
    drawnow
end

with this:

a1 = subplot(1,2,1);
a2 = subplot(1,2,2);
while 1
   plot(a1, rand(3))
   plot(a2, rand(3))
   drawnow
end

For more information, see “Judicious Object Creation”.