I have a code that is generating some numerical data in the form of a list of trajectories. Each trajectory itself is a list of 2D coordinates. Each coord. is a list of 2 numbers.(see example data below)
The code can write this data to a file adding adequate braces and commas so that if the output was to be copy-pasted into a mathematica notebook, it would correctly parse as a list of list of list, ignoring white-space.
The problem is that copy-pasting isn't convenient for larger file sizes. So, is there a format in which i should export my data so that a corresponding import command would recognize it as a list of list of list?What would be the corresponding import command?
So far I have realized that tab separated format with Import[filePath,"Table"]
will work for 2D arrays. On the other hand,"list like output format" when directly imported doesn't parse properly. I did found a question on se regarding importing 3D lists but they had been exported from Matlab first, which I am not using.
To be clear, I can output the numbers in any way I want-with/without braces, multiline, single line, comma/tab separated etc. I just need to know a format that would be properly read as a 3D list.
Here's an example output
(ignoring whitespace this is of the form{{a,b},{c},{d,...}...}
)
{Nothing
,
{{0.5,0.0}
}
,
{{0.51,0.031415926535897934}
,{0.4990133642141358,0.03139525976465669}
}
,
{{0.52,0.06283185307179587}
,{0.5070210091497347,0.06337709934111496}
}
,
{{0.53,0.0942477796076938}
,{0.5150286540853336,0.09535893891757323}
}
,
{{0.54,0.12566370614359174}
,{0.5230362990209325,0.1273407784940315}
}
,
{{0.55,0.15707963267948966}
,{0.5310439439565314,0.15932261807048975}
}
,
{{0.56,0.18849555921538758}
,{0.5390515888921303,0.19130445764694803}
}
,
{{0.5700000000000001,0.2199114857512855}
,{0.5470592338277293,0.22328629722340632}
}
,
{{0.5800000000000001,0.2513274122871834}
,{0.5550668787633282,0.2552681367998646}
}
,
{{0.5900000000000001,0.28274333882308134}
,{0.5630745236989271,0.2872499763763229}
}
}
Import[filePath, "List"]
? $\endgroup$list = copy/paste from your post
.text = ExportString[list, "Text"];
listImport = ImportString[text, "List"]
. Apart fromNothing
,list
andlistImport
are identical. $\endgroup$