【发布时间】:2019-02-07 04:16:34
【问题描述】:
我正在尝试了解 Matlab 中的 Movie 是如何工作的,我以前从未使用过它。我有一个热方程的代码,它可以找到我决定放在物体(杆)长度上的段数量的温度。但是,我能够绘制一个显示不同条件下所有值的正常图。我在左场试图了解如何将其变成电影。
A=0.1; %Diffusivity or conductivity (switching for variable K)
L=1; %Length of rod
dt= 10^(-4); %value of timestep
X=100; %Wants to Discretize rod into 100 separate sections
t= 10; % 50 timesteps will be taken (dt)
dx=L/X; %delta X needed for the heat equation for this case Pi/100
x1=linspace(0, L, X); %Take 100 equally spaced sections between 0 and L
y1=linspace(0, t, 51);
T1= zeros(X,t); %set a X x t matrix of zeros
%Set boundary and initial conditions
%T0=0; Ends of rod temperature are 0
%TL=0;
%Create a for loop to continuously solve the heat equation until time is up
for i= 2:X-1 %X-1 because we already know initial point
for j=1:50 % used to update heat equation each step
T1(:,1)= sin((pi*x1(i))/L);%start solving the heat equation at second
% value in the matrix in column 1 (skip
% 1st because we have initial condition)
T1(1,:) = 0; %Gives the first column = 0
T1(100,:) = 0; %Gives last column = 0 just as initial conditions state
%Heat Equation for T^n+1 (i)
T1(i,j+1)= A*dt*((T1(i+1,j)-2*T1(i,j)+T1(i-1,j)/dx^2))+ T1(i,j);
end
end
figure(1)
plot(x1,T1);
【问题讨论】:
-
我希望它能够一次铺设一层
-
你需要使用
movie吗?为什么不对每个跟踪使用plot和hold on,在每个跟踪的末尾使用pause? -
@rayryeng 最终产品必须是电影格式...我可以使用 plot hold on 和 hold off 然后将每个跟踪保存到文件夹中播放吗?
-
不,但您可以使用
getframe捕获每个情节。虽然效率很低,但我可以提供答案。 -
@rayryeng 一个例子会很棒!