0
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Can you please provide the actually file that you are importing? $\endgroup$ – Öskå Jun 2 '14 at 12:01
  • $\begingroup$ 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. $\endgroup$ – MaxJ Jun 2 '14 at 12:46
  • $\begingroup$ 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. $\endgroup$ – Öskå Jun 2 '14 at 12:48
  • $\begingroup$ OK I added the file $\endgroup$ – MaxJ Jun 2 '14 at 12:53
  • $\begingroup$ Does it work if you use {{#1, #2}, {#3, #4}} & @@@ #[[All, 1 ;; -1 ;; 4]] &/@Arrows? $\endgroup$ – kglr Jun 2 '14 at 13:21
1
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Thank you I will try to implement it in my program $\endgroup$ – MaxJ Jun 2 '14 at 15:57

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.