0

I have a bunch of coordinates given in a file. The file contains Startpoints and Endpoints of arrows in columns(Example):

t    start1    end1    start1   end2   
1    1  2     2  2    0  0     1  1
2    0  0     1  4     

Where the number of arrows is not constant over time. I tried to read the file like this and it did not work (especially the No_of_columns which gives the number of columns for a given row should depend on the row number as each row does not contain the same number of coordinates):

{{#1, #2}, {#3, #4}} & @@@ #[[All, 1 ;; No_of_columns(row) ;; 4]] &/Arrows;

I could also output another file stating the number of coordinate pairs in each row:

t   No_of_arrows

So basically I need a matrix whose column number is not the same for all rows. Is that even possible?

EDIT:

https://www.dropbox.com/s/xuuc6v0az73k49e/arrows.txt

EDIT2:

I will try to be more specific. I created (with a lot of help) a code animating rectangles movement in 2D. In the next step I want to connect those rectangles by arrows. Importantly those arrows come and go so that I would have to give another file stating the number of arrows at each time point (maybe?).

So for now I need data looking like this (?)

Arrow_coordinates={{{{1,2},{2,2}},{{0,0},{1,1}}},{{{0,0},{1,4}}}} 

In this case I could run an animation with 2 arrows in the first step and 1 in the second step.

Animation of moving rectangles in 2D from data file

MaxJ
  • 1,535
  • 1
  • 10
  • 16
  • Can you please provide the actually file that you are importing? – Öskå Jun 02 '14 at 12:01
  • Its just a huge file with several thousand lines which I need another computer to produce. For now I am experimenting with the 2 lines above, where the first one contains 2 arrows and the 2nd one only one. – MaxJ Jun 02 '14 at 12:46
  • Then provide a text file with a few lines formatted in the same way as your huge file.. :) Because here you have spaces, you may have tabulations in your text file. – Öskå Jun 02 '14 at 12:48
  • OK I added the file – MaxJ Jun 02 '14 at 12:53
  • Does it work if you use {{#1, #2}, {#3, #4}} & @@@ #[[All, 1 ;; -1 ;; 4]] &/@Arrows? – kglr Jun 02 '14 at 13:21
  • oh sorry I forgot to scroll ^^ will have a look now – MaxJ Jun 02 '14 at 15:53

1 Answers1

1

I don't know if I understood your issue correctly but here is what I propose:

data = Import["http://pastebin.com/raw.php?i=1Wmx3GKH", "Data"];
partInTwo = Partition[#, 2] &;
arrows = partInTwo /@ partInTwo /@ ToExpression /@ StringSplit /@ data;
SeedRandom@222;
col = ColorData["Rainbow"]@RandomReal[] & /@ Range@Length@arrows;
Graphics[Thread@{col, Arrow /@ arrows}, ImageSize -> 200, Frame -> True]

Mathematica graphics

Öskå
  • 8,587
  • 4
  • 30
  • 49