1
$\begingroup$

I have several functions f_i[a,b,x] I would like to export as an .avi file. They should be plotted with x as the variable and multiple arbitrary parameter pairs {{a1,b1},{a2,b2},...} of the animation. What I tried so far:

Export ["testfile.avi", Table[Table[{
Plot[Sin[(a + x/2)*x], {x, 0, 30}],
Plot[Cos[(a + x/2)*x], {x, 5, 30}],
Plot[b*Cos[(a + x/2)*x + b], {x, 5, 30}]}], {a, 0.1, 1, 0.1}]]

This gives an .avi file where the parameter a is run from 0.1 to 1 in steps of 0.1. However, I would like to have an .avi file, where the plots with the arbitrary parameter pairs {{a1,b1},{a2,b2},...} are displayed in the individual frames. How is the syntax for this?

I do have a table of the parameter pairs in Excel. Is there any way to import them conviniently?

P.S.:The actual functions are a bit more complicated, so this is a simplified example in case you are wondering.

$\endgroup$
  • $\begingroup$ What do you want with b? it is undefined. Would something like PlotLabel[ ToString[a]<>","<>ToString[b]] work for you? $\endgroup$ – Ruud3.1415 Jan 24 '18 at 13:43
  • $\begingroup$ a and b are a pairs of arbriary values, which I have saved in an Excel table. $\endgroup$ – JPK Jan 24 '18 at 14:09
  • $\begingroup$ JPK, welcome to mma.se! We suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign. $\endgroup$ – kglr Jan 24 '18 at 16:05
1
$\begingroup$

You can us

 Export ["testfile.avi", frames1] (* or *)
 Export ["testfile.avi", frames2]

where frames1 is obtained using Join on the output of nested Tables:

frames1 = Join @@ Table[Table[{Plot[Sin[(a + x/2)*x], {x, 0, 30}], 
  Plot[Cos[(a + x/2)*x], {x, 5, 30}], Plot[b*Cos[(a + x/2)*x + b], {x, 5, 30}]}, 
  {b, .1, 1, .1}], 
  {a, 0.1, 1, 0.1}];

and frames2 is obtained using a single Table with a 2D iterator:

frames2 = Table[{Plot[Sin[(ab[[1]] + x/2)*x], {x, 0, 30}], 
    Plot[Cos[(ab[[1]] + x/2)*x], {x, 5, 30}], 
    Plot[ab[[2]]*Cos[(ab[[1]] + x/2)*x + ab[[2]]], {x, 5, 30}]}, {ab, 
    Tuples[Range[0.1, 1., 0.1], 2]}];

frames1 == frames2

True

$\endgroup$
  • $\begingroup$ Thank, this is exactly what I was looking for. $\endgroup$ – JPK Jan 24 '18 at 15:55
  • 1
    $\begingroup$ @JPK I know this is far after the fact, but in general if an answer solves your problem it is polite to upvote it and, potentially, accept it as a solution to indicate that your problem was solved. $\endgroup$ – b3m2a1 Jul 24 '18 at 4:41

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.