-3

I am really a beginner to make a movie. I need to make a movie from a bunch of plots. How I can make it. I have 8 plots , which are y versus x. I want to make movie based on x to see how y change with increasing x.

Please consider my matlab file is as below:

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)

I wrote following as a simple example but it does not work:

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

In a nut shell , How I can make a movie like Fig. 3.2: in the following link

mustaccio
  • 18,234
  • 16
  • 48
  • 57
user3271929
  • 317
  • 2
  • 4
  • 11

1 Answers1

1

The basic code for making a movie from a given figure is like this:

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

Look into the help files for getframe and movie to see what other options are available. To save a movie out, see movie2avi.

Note that for a given figure you only need to call hold on once. If all your y values are of the same length, then you can re-write your code/plotting more efficiently like this:

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
nkjt
  • 7,825
  • 9
  • 22
  • 28
  • Thank you a lot. How I can save final figure in order to show like movie in my presentation? – user3271929 Feb 07 '14 at 07:23
  • I wrote following as a simple example but it does not work: Please look at on my edited question – user3271929 Feb 07 '14 at 07:31
  • In your current loop you're just repeating `plot(x,y)` over and over so all the frames of the movie are the same. That's why I showed the `plot(x,y(n,:))` syntax. `n` is just a single number. – nkjt Feb 07 '14 at 12:00
  • What I have to put "for n = 1:?" in the question mark place: – user3271929 Feb 07 '14 at 12:28
  • depends how many frames you have. Why not try a few different numbers and see what happens? – nkjt Feb 07 '14 at 13:23
  • How I can make a movie like Fig. 3.2: in the following [link](http://www.physics.cit.ie/photonics/photonic_device_dynamics_group/Techniques.html) – user3271929 Feb 09 '14 at 16:19