I am currently solving PDEs for a discrete vector field with C++. The output at a time t is an array where each row represents a site and there are 6 columns, the first 3 give the position of the site and the last 3 give the components of the vector in that site.

I already managed to pick one file and plot it so that I get a nice visualization.

What I want to do now is to pick several data sets, A_0 to A_100, and make an animation with it.

This is the code I have:

mmm = ReadList["A_49.txt", Number, RecordLists -> True];

pos = Table[{mmm[[i, 1]], mmm[[i, 2]], mmm[[i, 3]]}, {i, 1, Length[mmm]}];
b = Table[{mmm[[i, 4]], mmm[[i, 5]], mmm[[i, 6]]}, {i, 1, Length[mmm]}];

figure = Table[arrow[pos[[i]], b[[i]], ColorData["DarkRainbow"]
         [(b[[i]].{0,0,1} + 1)/2]], {i, 1, Length[pos]}];

Show[figure, Boxed -> False, ViewPoint -> {0, 0, 10}]

Sorry if this is easy, I'm new to both animations and Mathematica.

Thanks for your help.

  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) 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! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey Apr 19 '15 at 4:04
  • $\begingroup$ Thanks bbgodfrey! I just took the tour. I liked the simplicity and the privileges-system. I'll make my best to become a useful member of the community. $\endgroup$ – Felipe P. Apr 19 '15 at 4:10

You can make a function that plots the content of a file like this:

plot[file_] := Module[{mmm, figure, pos, b},
    mmm = ReadList[NotebookDirectory[] <> file, Number, RecordLists -> True];
    (* ... the rest of your code. *)

To make an animation you have to first create a list with all the "frames", then you can display it with ListAnimate or export it as a gif using Export.

frames = plot / @ Table["A_" <> ToString@i <> ".txt", {i, 0, 100}];
  • $\begingroup$ Hey @pickett, thanks for your answer, but it gives me an error: `StringJoin::string: "String expected at position 2 in A_ <> 0 <> .txt" $\endgroup$ – Felipe P. Apr 19 '15 at 15:40
  • $\begingroup$ @FelipeP. My mistake, fixed it. $\endgroup$ – C. E. Apr 19 '15 at 17:44

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.