function create_simulation( matrix_all,timesteps,num_agents )
mkdir('movies');
filename_mov='.\movies\vid1';
vidObj = VideoWriter(filename_mov,'Motion JPEG AVI');
set(vidObj,'Quality',100,'FrameRate',2);
%matrix_all='time','id','xcor','ycor'
time=matrix_all(:,1);
id=matrix_all(:,2);
x=matrix_all(:,3);
y=matrix_all(:,4);
colors=jet(num_agents);
min_x=min(x);max_x=max(x);min_y=min(y);max_y=max(y);
f=figure('renderer', 'zbuffer');
a = axes('Parent',f);
axis(a,'tight');
set(a,'nextplot','replacechildren');
open(vidObj);
for t=1:timesteps,
t_filter=time==t;
scatter(x(t_filter),y(t_filter),[],colors,'filled');
xlim([min_x max_x]);
ylim([min_y max_y]);
xlabel(num2str(t));
drawnow;
writeVideo(vidObj, getframe(f));
end
close(vidObj);
end
The above code creates a movie just recording the first frame every time only. I have tried these answers,(as you can see in code) but no success.
Data(some of it):
>>matrix_all
1 1 680.640000000000 898.650000000000
1 2 754.610000000000 832.080000000000
1 3 864.500000000000 935.870000000000
1 4 752.080000000000 1023
1 5 728.080000000000 1052.10000000000
1 6 787.900000000000 1030.60000000000
2 1 678.170000000000 898.650000000000
2 2 754.610000000000 832.080000000000
2 3 864.500000000000 935.870000000000
2 4 752.080000000000 1023
2 5 728.080000000000 1052.10000000000
2 6 787.900000000000 1030.60000000000
3 1 678.170000000000 898.650000000000
3 2 754.610000000000 832.080000000000
3 3 864.500000000000 935.870000000000
3 4 752.080000000000 1023
3 5 728.080000000000 1052.10000000000
3 6 787.900000000000 1030.60000000000
4 1 678.170000000000 898.650000000000
4 2 754.610000000000 832.080000000000
4 3 864.500000000000 935.870000000000
4 4 752.080000000000 1023
4 5 728.080000000000 1052.10000000000
4 6 787.900000000000 1030.60000000000
>> create_simulation( matrix_all,4,6)
Worst case I will have to write all images to disk and create a movie of it.