I have the following dataset:
partitionedPts = {{{{180, 100}, {274.33`, 100}}, {{274.33`,
98.90028`}, {274.33`, 98.02906`}}, {{180, 98.90028`}, {274.33`,
98.90028`}}}, {{{274.33`, 100}, {457.645`, 100}}, {{457.645`,
98.02906`}, {457.645`, 85.9109`}}, {{274.33`,
98.02906`}, {457.645`, 98.02906`}}}, {{{457.645`,
100}, {492.329`, 100}}, {{492.329`, 85.9109`}, {492.329`,
81.68262`}}, {{457.645`, 85.9109`}, {492.329`,
85.9109`}}}, {{{492.329`, 100}, {681.938`, 100}}, {{681.938`,
81.68262`}, {681.938`, 80.13062`}}, {{492.329`,
81.68262`}, {681.938`, 81.68262`}}}, {{{681.938`,
100}, {862.401`, 100}}, {{862.401`, 80.13062`}, {862.401`,
78.64416`}}, {{681.938`, 80.13062`}, {862.401`,
80.13062`}}}, {{{862.401`, 100}, {985.038`, 100}}, {{985.038`,
78.64416`}, {985.038`, 77.63547`}}, {{862.401`,
78.64416`}, {985.038`, 78.64416`}}}, {{{985.038`,
100}, {1087.85`, 100}}, {{1087.85`, 77.63547`}, {1087.85`,
76.49579`}}, {{985.038`, 77.63547`}, {1087.85`,
77.63547`}}}, {{{1087.85`, 100}, {1117.983`, 100}}, {{1117.983`,
76.49579`}, {1117.983`, 76.47131`}}, {{1087.85`,
76.49579`}, {1117.983`, 76.49579`}}}}
and currently this code to transform it into gnuplot
code to print arrows:
arrows =
StringJoin["set arrow " ~~ #[[1]] ~~ " " ~~ #[[2]]] & /@
Transpose[{Map[ToString,
Range@Length@#, {-1}], #} &@(StringJoin[
"from first " ~~ #[[1, 1]] ~~ "," ~~ #[[1, 2]] ~~
" to first " ~~ #[[2, 1]] ~~ "," ~~ #[[2, 2]]] & /@
Flatten[Map[ToString, partitionedPts, {-1}], 1])]
Which produces:
{"set arrow 1 from first 180,100 to first 274.33,100",
"set arrow 2 from first 274.33,98.9003 to first 274.33,98.0291",...}
But I would like to produce this one:
{"set arrow 1 arrowstyle 1 from first 180,100 to first 274.33,100",
"set arrow 2 arrowstyle 2 from first 274.33,98.9003 to first 274.33,98.0291",
"set arrow 3 arrowstyle 3 from first 180,98.9003 to first 274.33,98.9003",
"set arrow 4 arrowstyle 1 from first 274.33,100 to first 457.645,100",
"set arrow 5 arrowstyle 2 from first 457.645,98.0291 to first 457.645,85.9109",
"set arrow 6 arrowstyle 3 from first 274.33,98.0291 to first 457.645,98.0291", ...}
I am trying something along the lines (i was thinking of named slots one would use the array partitionedPts
and the other would just use {1,2,3}
:
Outer[StringJoin[
"arrowstyle "~~#2~~" from first " ~~ #1[[1, 1]] ~~ "," ~~ #1[[1, 2]] ~~
" to first " ~~ #1[[2, 1]] ~~ "," ~~ #1[[2, 2]]] &,
Transpose[Map[ToString, partitionedPts, {-1}]], {1, 2, 3}]
I have gone through all the options that I know but I admit, this is the type of problem that i always get stuck with, when i have multiple list of variable depth. This is so trivial to do with for loops and so complicated in mathematica's illegible @/_&
style but I prefer to learn the mathematica way.
Dimensions@partitionedPts
gives{8, 3, 2, 2}
. In your title you refer tovariable depth lists
. Please elaborate. $\endgroup${1,2,3}
is{3}
and I want it to insert inside one of the diemnsions ofpartitionedPts
and repeat. $\endgroup$