【发布时间】:2015-10-21 19:54:16
【问题描述】:
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
上面的代码每次只创建一个只记录第一帧的电影。我试过这些answers,(你可以在代码中看到)但没有成功。
数据(部分):
>>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)
最坏的情况下,我将不得不将所有图像写入磁盘并创建一个电影。
【问题讨论】:
-
你能给我们提供这个复制的数据吗? matrix_all, timespteps,num_agents.
-
@AnderBiguri 感谢您的回复!请检查我已经发布了一些数据。我不认为这个问题会具体到数据。
-
对不起,您不明白。我们不想查看您的数据,我们想要一段代码,如果我们通过复制粘贴来尝试的话。
-
@AnderBiguri 请检查一下我已经添加了对函数的调用。
-
是的,对不起。下次尝试使用我们可以看到的数据,这对所有人来说都更容易。
标签: matlab animation video figure