2
$\begingroup$

I have a list of vectors in Mathematica which I want to write into a text file such that POVray can read them as vectors.
The list of vectors looks something like this:
H = {{3,3,3,3},{4,4,4,4},{5,5,5,5}}
I know that I can use
Export["filename.txt", H, "Table", "FieldSeparators" -> "," ];
to have the output file look like the following:
3,3,3,3
4,4,4,4
5,5,5,5
I also know that POVray recognizes vectors as <3,3,3,3>.
My question now is,
is there some rule that works the same as FieldSeperators (maybe something like BeginOfLineSeperators and EndOfLineSeperators) such that i can get the output file to have rows like <3,3,3,3> instead of 3,3,3,3?
Or is there any other way of doing this easily?

All help is appreciated

$\endgroup$
  • $\begingroup$ About how many vectors are you looking at? This shouldn't be too hard, but if you have tons of them the performance might need thinking about. $\endgroup$ – Carl Lange Sep 30 '20 at 21:09
  • $\begingroup$ My real lists contains 20 vectors for now, but I will also be using an instance where my list contains 2400 vectors. So it differs. $\endgroup$ – Rick Oct 1 '20 at 7:49
  • $\begingroup$ The posted solution by creidhne will definitely work fine for either case. $\endgroup$ – Carl Lange Oct 1 '20 at 8:23
3
$\begingroup$

Use ExportString in place of Export, replace the start and end of each line to form POV lists, and then export to a text file.

txt = ExportString[H, "Table", "FieldSeparators" -> ","];
pov = StringReplace[txt, {StartOfLine -> "<", EndOfLine -> ">"}];
Export["lists.pov", pov, "Text"]
$\endgroup$

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.