0
$\begingroup$

I have a function f(z,t) and I would like to animate it and also create a video file. For animation I do the following;

 Res1 = Sin[z t];
    vid = Animate[
    Plot[Res1, {z, 1, 2}, PlotRange -> {0, 1.1}], {t, 0, 1/3}];
    Print[vid];

This is not working, I am just getting a blank animation. When I do;

vid = Animate[
Plot[Sin[z t], {z, 1, 2}, PlotRange -> {0, 1.1}], {t, 0, 1/3}];
Print[vid];

this is working. I don't see why the first version is not working.

I also would like to save this animation as a movie. I don't think I can directly save that as a movie, but I found this;

frame[t_]:=ArrayPlot[Table[Sin[z t],{z,1,2}]];
frames=ParallelTable[frame[t],{t,0,1/3}];
Export["1stvid.mov",frames];

And I get an error. I am a little lost, I appreciate it some guidance.

$\endgroup$
1
  • $\begingroup$ the last error is unrelated to animation, your ArrayPlot expression is just wrong. (Its not even clear how to fix) $\endgroup$
    – george2079
    Apr 15, 2017 at 19:20

2 Answers 2

2
$\begingroup$

It is a scoping issue. You need to add arguments to Res1 so that z and t have the same meaning inside the Animate

Res1[z_, t_] = Sin[z t];
vid = Animate[
  Plot[Res1[z, t], {z, 1, 2}, PlotRange -> {0, 1.1}], {t, 0, 1/3}]

enter image description here

Click on image above.

Export vid in whatever desired format.

$\endgroup$
1
  • $\begingroup$ Beautiful, thank you. $\endgroup$
    – Erdem
    Apr 15, 2017 at 19:03
2
$\begingroup$

I tend to just generate frames and Export:

frames = Table[
   Plot[Sin[z t], {z, 1, 2}, PlotRange -> {0, 1.1}],
   {t, 0, 1/3, 1/60}];
Export["test.avi", frames]

This lets us control exactly how many frames are generated, while Animate figures that automatically.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.