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
-
$\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 LangeSep 30, 2020 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$– RickOct 1, 2020 at 7:49
-
$\begingroup$ The posted solution by creidhne will definitely work fine for either case. $\endgroup$– Carl LangeOct 1, 2020 at 8:23
1 Answer
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"]