In this video, I'll explain
my graphics code for
creating a video of the Karman vortex street.
Let's have a look.
I write the graphics code as a function,
with no input or output arguments.
It should work well for a Reynolds number equal to 60.
First, we initialize our movie file.
I use the MATLAB function VideoWriter.
We are creating a file called
movie.mp4 using the MPEG-4 format.
I specify the quality to be its maximum value,
and I specify the frame rate to be 24 frames per second.
We use the open command to open the file,
and I specify which fields that we're going to
plot and add to the movie file as frames.
There's a subdirectory called fields.
In this subdirectory, I have saved MATLAB
MAT files called Re_60_number,
where the number designates the flow evolution time.
Next, we loop over all the saved fields to
construct the plots and put
the frames into the movie file.
Here, for example, there are 1,000 fields,
so we're going to loop over from 1-1,000.
We load the MATLAB MAT files that contain
the scalar vorticity fields in the Omega variable.
Omega is a matrix with the value of
the scalar vorticity on the N by M grid.
Here, I load the input file,
which is the base name of the fields,
and add it to the number that will go from 1-1,000.
I've saved 1,000 math files containing
1,000 timesteps of the scalar vorticity field.
Then we have the main part of the code,
which you've already seen when you did
the graphics for the steady solution.
We define the Xi,
Theta grid, we define the x, y grid,
we construct interpolation points,
and we interpolate from the Xi,
Theta grid to the x, y grid.
We set Omega equal to zero inside the cylinder.
We set the colormap.
We plot the color contours using imagesc,
plotting Omega here in the x, y space.
We draw a black circle for the cylinder,
and then we neaten up the plot.
Here, I'll write in text
the evolution time of the field.
What's being saved here are the Omega fields from time 1,
2, 3, all the way to time 1,000.
You can modify this if you want
to save different timesteps.
Finally, we need the code that
adds the frame to the movie file.
We use the MATLAB function, getframe.
We get the current frame and call it frame.
What we're doing is screen
capturing the plot we just made on
the computer and then writing
that frame into the movie file.
This is inside the loop,
so we're just writing successive frames.
Here, we'll be writing 1,000 frames into
the movie file with 24 frames per second being played.
The close command refers to the plot that we just made
so we don't end up with a
1,000 open plots on the computer.
Since this program takes a while to run,
I like to keep track of where we are in the program,
so I print out the number of
the field that we're currently plotting.
When the loop finishes,
we close the movie file,
and the program is done.
I hope this has given you some idea on how
to construct a movie file in MATLAB.
You can pass the grader
without computing the Karman street,
but you should give it a try.
It's a more lengthy computation,
and you may need to run your code overnight.
I'm Jeff Chasnov.
Thanks for watching,
and I'll see you in the next video.