Maybe you could try a timer. Have a look for 'Timer' in Matlab's documentation. There are many examples and it is not hard at all!
Furthermore,
- It doesn't make sense to update your graph 1000 times per second (which is what you seem to try above). 30 Times per second is usually enough to get the impression that the animation is fluently.
- The example above is a little silly, x is a scalar, and plotting a scalar doesn't really make sense (or do you want the plot to act like a moving point? If so, consider using the function comet (it may do exactly what you want).
- In order to improve performance dramatically, you should do a plot command once and then update the data of the plot. Otherwise, you will never get a nice animation. It could be the case that this point alone solves your drawnow problem. Using this, the above code would be:
global x
global P % Handle to the plot
x=0;
P=plot(0,0,'r'); % initialize plot. The data does not matter
for k=1:1000
x=x+1;
pause(0.001)
end
function axes1_CreateFcn(hObject, eventdata, handles)
global x
global P
set (P,'xdata',x,'ydata',x.^2) % Note the .^ in order to do element-wise power instead of matrixwise power