Reputation: 101
I am attempting to create an animated graph by plotting specific points form 2 column vectors buy am having issues.
I have attempted to use the pause, drawnow, changing my vectors and am still having trouble with my code not working. I have got my vector in a for loop which specifies the points needing to be plotted.
Using ODE45 I have made a column vector with 2 rows.
grid on
func=plot(t,x);
%set(gca,'XLim',[0 tmax])
for i=1:length(x)
set(func,'XData',x(1,i),'YData',x(2,i));
drawnow
end
I expect the output to be an animated graph, but currently, all that I'm getting is either a nonanimated graph, or a bunch of errors saying that I am exceeding the array bounds.
Upvotes: 0
Views: 71
Reputation: 6863
You are using plot
with a single point. The default plotting style for plot
is to not show individual points, but to connect the input data with lines.
Either change the LineSpec
property to e.g. 'o'
:
func = plot(x(1,1), x(2,1), 'o');
or use the scatter
function to plot individual points:
func = scatter(x(1,1), x(2,1));
Upvotes: 3