MATLAB: How to draw Interval animation

animationgraph

Hi I'm trying to plot a graph of y=x, y=-x, y=0, x=0
and a ball on each plot goes back and forth interval of -1 to 1.
I've been searching internet to see any similar animation but failed to find any.
Can someone give me an advise on how to even draw a ball model that oscillate?
Thank you

Best Answer

One possibility:
x = linspace(-1, 1, 75);
y = -x.^2;
figure(1)
for k2 = 1:2
for k1 = 1:length(x)
plot(x(k1)*(-1)^k2, y(k1), 'ob', 'MarkerFaceColor','r')
axis([min(x) max(x) min(y) max(y)])
refreshdata
drawnow
end
end
It redraws the plot for each position of the ball. Experiment to get the result you want. See the documentation for the various functions for the details of how it works.