在Matlab中制作电影并将其导出为电影文件
毫无疑问,这个问题已经被提出了;然而,经过一段时间的搜索,我找不到任何与我的情况有关的东西 我要做的是制作一部通过for循环生成的情节电影,然后导出这个电影文件。我该怎么做?以下是我的代码的主要部分:在Matlab中制作电影并将其导出为电影文件,matlab,matrix,plot,movie,Matlab,Matrix,Plot,Movie,毫无疑问,这个问题已经被提出了;然而,经过一段时间的搜索,我找不到任何与我的情况有关的东西 我要做的是制作一部通过for循环生成的情节电影,然后导出这个电影文件。我该怎么做?以下是我的代码的主要部分: for j=1:N a=randi(L); b=randi(L); c=randi(L); d=randi(L); e=randi(L); f=randi(L); % Calcula
for j=1:N
a=randi(L);
b=randi(L);
c=randi(L);
d=randi(L);
e=randi(L);
f=randi(L);
% Calculate energy at positions
if lattice(a,b,c)==1 && lattice(d,e,f)==0
%latticenew=lattice;
%latticenew(d,e,f)=1;
%latticenew(a,b,c)=0;
E2=EnergyMC_1(lattice,mu,eps);
dE = E2-E1; %Change in total energy of the system (gas)
%as the particle goes from its current positon to the randomly
%selected position.
%DeltaE = [DeltaE,dE];
%Nsteps=Nsteps+1; %What does Nsteps do?
if rand<exp(-dE*beta) %Factor of K is in there to reduce
%the inverse temperature beta, so that the for loop can
%be longer than 15 iterations.
lattice(d,e,f)=1;
lattice(a,b,c)=0;
%lattice=latticenew;
E1=E2;
Accepted=Accepted+1;
%drawnow
[x,y,z] = ind2sub(size(lattice),find(lattice==1));
%position = [x,y,z];
%timelattice(:,:,j)=position;
plot3(x(:),y(:),z(:),'r.')
grid
%This is where the plotting occurs
end
HistoryE=[HistoryE, E1];
end
waitbar(j/N,H);
end
我真的不明白他们在说什么。这是我最新更新的代码:
for j=1:N
a=randi(L);
b=randi(L);
c=randi(L);
d=randi(L);
e=randi(L);
f=randi(L);
% Calculate energy at positions
if lattice(a,b,c)==1 && lattice(d,e,f)==0
%latticenew=lattice;
%latticenew(d,e,f)=1;
%latticenew(a,b,c)=0;
E2=EnergyMC_1(lattice,mu,eps);
dE = E2-E1; %Change in total energy of the system (gas)
%as the particle goes from its current positon to the randomly
%selected position.
%DeltaE = [DeltaE,dE];
%Nsteps=Nsteps+1; %What does Nsteps do?
if rand<exp(-dE*beta) %Factor of K is in there to reduce
%the inverse temperature beta, so that the for loop can
%be longer than 15 iterations.
lattice(d,e,f)=1;
lattice(a,b,c)=0;
%lattice=latticenew;
E1=E2;
Accepted=Accepted+1;
[x,y,z] = ind2sub(size(lattice),find(lattice==1));
%position = [x,y,z];
%timelattice(:,:,j)=position;
%drawnow
plot3(x(:),y(:),z(:),'r.')
%camorbit(1+j/10000,0);
grid
F=getframe(fig);
aviobj = addframe(aviobj,F);
end
HistoryE=[HistoryE, E1];
close(fig);
aviobj = close(aviobj);
end
%waitbar(j/N,H);
end
j=1时的:N
a=兰迪(L);
b=兰迪(L);
c=兰迪(L);
d=兰迪(L);
e=兰迪(L);
f=兰迪(L);
%计算各个位置的能量
如果晶格(a,b,c)==1&&晶格(d,e,f)==0
%latticenew=晶格;
%latticenew(d,e,f)=1;
%latticenew(a,b,c)=0;
E2=能量μ1(晶格,μ,eps);
dE=E2-E1;%系统总能量的变化(气体)
%当粒子从其当前位置随机移动到
%选定的位置。
%DeltaE=[DeltaE,dE];
%Nsteps=Nsteps+1;%Nsteps做什么?
如果rand在“这是绘图发生的地方”之后,写下:
代码结束后,您可以按照以下答案保存电影我编辑了我的帖子。你能看一下吗?也许我不够清楚。我已经知道你链接的帖子;我问这个问题的原因,尽管我知道,是因为我不明白答案。
for j=1:N
a=randi(L);
b=randi(L);
c=randi(L);
d=randi(L);
e=randi(L);
f=randi(L);
% Calculate energy at positions
if lattice(a,b,c)==1 && lattice(d,e,f)==0
%latticenew=lattice;
%latticenew(d,e,f)=1;
%latticenew(a,b,c)=0;
E2=EnergyMC_1(lattice,mu,eps);
dE = E2-E1; %Change in total energy of the system (gas)
%as the particle goes from its current positon to the randomly
%selected position.
%DeltaE = [DeltaE,dE];
%Nsteps=Nsteps+1; %What does Nsteps do?
if rand<exp(-dE*beta) %Factor of K is in there to reduce
%the inverse temperature beta, so that the for loop can
%be longer than 15 iterations.
lattice(d,e,f)=1;
lattice(a,b,c)=0;
%lattice=latticenew;
E1=E2;
Accepted=Accepted+1;
[x,y,z] = ind2sub(size(lattice),find(lattice==1));
%position = [x,y,z];
%timelattice(:,:,j)=position;
%drawnow
plot3(x(:),y(:),z(:),'r.')
%camorbit(1+j/10000,0);
grid
F=getframe(fig);
aviobj = addframe(aviobj,F);
end
HistoryE=[HistoryE, E1];
close(fig);
aviobj = close(aviobj);
end
%waitbar(j/N,H);
end
Mymovie(j)=getframe;