Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
Can you please provide the actually file that you are importing? –  Öskå Jun 2 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. –  user3683367 Jun 2 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 2 at 12:48
    
OK I added the file –  user3683367 Jun 2 at 12:53
    
Does it work if you use {{#1, #2}, {#3, #4}} & @@@ #[[All, 1 ;; -1 ;; 4]] &/@Arrows? –  kguler Jun 2 at 13:21

1 Answer 1

up vote 1 down vote accepted

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

share|improve this answer
    
Thank you I will try to implement it in my program –  user3683367 Jun 2 at 15:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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