0
$\begingroup$

I am running an animation with the following command:

files = FileNames[NotebookDirectory[] <> "*.dat"]; 
MTnumbers = FileNames[NotebookDirectory[] <> "MTnumbers.txt"];

data = Import[#, "Table"] & /@ files
MT = Import[#, "List"] & /@ MTnumbers


coords = {{#1 - (#3/2), #2 - (height/2)}, {#1 + (#3/2), #2 + (height/
       2)}} & @@@ #[[All, 2 ;;]] & /@ data;

height = 2;

colors = {Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, 
Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, 
Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue, 
Blue, Blue, Blue, Blue, Blue, Blue, Blue, Blue};
Animate[Graphics[{Sequence @@ {colors[[#]], 
   Rectangle @@ (coords[[#]][[t]])} & /@ MT[[1]]},
PlotRange -> {{-1000, 1000}, {-200, 200}}, 
ImageSize -> {1000, 200}], {t, Range[0, 7000]}] 

Export["tubuli.avi", %];

As soon as I try to export this output Mathematica crashes. When I increase the number of rectangles to about 150 the simulation crashes without giving an output. Is my computer too weak or am I doing something wrong?

EDIT:

The data is in the following zip archive you just need the notebook and the data in the same folder and it should work.

https://www.dropbox.com/s/iegdb1a031i4mn6/data.zip

$\endgroup$
10
  • $\begingroup$ IMO you should just provide the lists of coords and MT. You can put them on pastebin so Mathematica can Import them. If not, you can paste them here and I will put them on pastebin. $\endgroup$
    – Öskå
    Commented Jun 3, 2014 at 10:47
  • $\begingroup$ I edited the post. Gif export also crashes or returns a non moving gif. Do you know if it is possible add the command from this Answer mathematica.stackexchange.com/questions/48971/animating-arrows into the animation or can't I combine sequence and thread in one graphic? $\endgroup$
    – MaxJ
    Commented Jun 3, 2014 at 13:01
  • $\begingroup$ yeah I thought so... But basically my data is equal to what is written in the file and the animation works but the export aborts. $\endgroup$
    – MaxJ
    Commented Jun 3, 2014 at 13:12
  • $\begingroup$ what i mean is: When I type data the output looks like the one in the file. Should I provide another format? $\endgroup$
    – MaxJ
    Commented Jun 3, 2014 at 13:33
  • $\begingroup$ @user3683367 You should test the code you post here ...:) $\endgroup$ Commented Jun 3, 2014 at 13:33

1 Answer 1

2
$\begingroup$

I don't really understand what is your issue here and your goal but tell me if that fits you:

datfiles=ToString@StringForm["MT_mathematica_``.dat",#]&/@Range@40;
MT=Range@40;
data=ToExpression@Import["Your/Path/Here"<>#]&/@datfiles;
height=2;
rect=Rectangle[Sequence@@#]&;
coords={{#1-(#3/2),#2-(height/2)},{#1+(#3/2),#2+(height/2)}}&@@@#[[All,2;;]]&/@data;
frames=Table[Graphics[{Blue,rect@coords[[1,t]]},PlotRange->{{-100,100},{-200,200}},Frame->True],{t,1,Length@First@coords,100}];
Export["~/MT.gif",frames,"DisplayDurations"->.1]

enter image description here

I reduced the number of frames and the ImageSize/PlotRange to see something.

$\endgroup$
4
  • $\begingroup$ Ok it worked like this for one rectangle. I will try to export all rectangles in 1 file now to see if it works. $\endgroup$
    – MaxJ
    Commented Jun 3, 2014 at 18:04
  • $\begingroup$ If it doesn't work it won't be because of Mathematica but because of your computer I'm afraid. $\endgroup$
    – Öskå
    Commented Jun 3, 2014 at 18:13
  • $\begingroup$ Ok thats fine I just needed to know if it it works before I put it on some better computer. So basically I can switch Blue => colors[[#]] and add & /@ MT[[1]] behind the"}" bracket and a gif involving all rectangles will be made? $\endgroup$
    – MaxJ
    Commented Jun 3, 2014 at 18:14
  • $\begingroup$ Just make sure that colors has the correct Length. But basically {colors[[#]],rect@coords[[#,t]]}& /@ MT[[1]] should do it. $\endgroup$
    – Öskå
    Commented Jun 3, 2014 at 21:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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