我真的是一个制作电影的初学者。我需要从一堆情节中制作一部电影。我怎么能做到。 我有8个图,它们是y对x。我想制作基于x的电影,看看y如何随着x的增加而改变。
请考虑我的matlab文件如下:
x=[1 1.2 1.4 2 3 4 5 7 9 10];
y1=[2.8 7.6 10.9 12.3 15.0 21 12.3 14.5 42.4 47.7];
y2=1e8.*[0.599e-7 0.607e-7 0.343e-7 0.3e-7 0.873e-8 0.578e-8 0.298e-8 0.725e-9 0.14e-8 0.478e-9];
y3=10.*[0.136 0.544 0.834 1.03 0.366 0.314 0.703 0.207 0.696 0.164];
y4=10.*[0.26 0.21 0.17 0.25 0.31 0.34 0.16 0.15 0.13 0.31];
y5=....
y6=...
y7=...
y8=[6 7.6 10.9 12.3 15.0 21 12.3 19.5 42.4 47.7 ];
plot(x,y1)
hold on
plot(x,y2)
hold on
plot(x,y3)
hold on
plot(x,y4)
hold on
plot(x,y5)
hold on
plot(x,y6)
hold on
...
plot(x,y8)
我将以下内容写成一个简单的示例,但它不起作用:
clc;clear all;
x=[1 1.2 1.4 2 3 4 5 7 9 10];
y = zeros(4,10);
y(1,:)=[2.8 7.6 10.9 12.3 15.0 21 12.3 14.5 42.4 47.7 ];
y(2,:)=1e8.*[0.599e-7 0.607e-7 0.343e-7 0.3e-7 0.873e-8 0.578e-8 0.298e-8 0.725e-9 0.14e-8 0.478e-9];
y(3,:)=10.*[0.136 0.544 0.834 1.03 0.366 0.314 0.703 0.207 0.696 0.164 ];
y(4,:)=10.*[0.26 0.21 0.17 0.25 0.31 0.34 0.16 0.15 0.13 0.31 ];
figure;
hold on
for n = 1:10
plot(x,y)
M(n)=getframe; % get frame from the current figure;
end
movie(M,10); %plays movie M 10 times
在坚果壳中,我如何制作如图3.2所示的电影:在以下link
答案 0 :(得分:1)
从给定的数字制作电影的基本代码如下:
figure;
hold on
for n = 1:20
plot(1:10,n*(1:10))
M(n)=getframe; % get frame from the current figure;
end
movie(M,10); %plays movie M 10 times
查看getframe
和movie
的帮助文件,了解其他可用选项。要保存电影,请参阅movie2avi
。
请注意,对于给定的数字,您只需要拨打hold on
一次。如果您的所有y
值都相同,那么您可以更有效地重写代码/绘图:
x=[1 1.2 1.4 2 3 4 5 7 9 10];
y = zeros(8,10);
% then this for each of your sets of y values
y(1,:) = [2.8 7.6 10.9 12.3 15.0 21 12.3 14.5 42.4 47.7 53 81.3 86.1];
...
y(8,:)=[6 7.6 10.9 12.3 15.0 21 12.3 19.5 42.4 47.7 53 81.3 86.1 ];
plot(x,y) % plots all the y's against x with automatic coloring
plot(x,y(n,:)) % plots just one set of y values against x