C. *_* E. 1 wolfram-mathematica
我对Mathematica很新.我想将它用作gnuplot的数据源(我知道Mathematica也可以绘图),它使用的文件格式包含列中的数据和每行上每列之间的空格.像这样:
x y
1 123
2 234
4 456
Run Code Online (Sandbox Code Playgroud)
等等
我来创建这个表达式:
{CountryData["G8"], CountryData[#, "GDP"] & /@ CountryData["G8"]} // Transpose // Grid
Run Code Online (Sandbox Code Playgroud)
这就像我想要的那样创建了一个表.现在,我如何将其导出到一个文件而不是矩阵,而是像Mathematica中出现的那样?
您CountryData可以使用map运算符简化您的使用/@:
{#, CountryData[#, "GDP"]} & /@ CountryData["G8"],
Run Code Online (Sandbox Code Playgroud)
将此与Export您结合得到:
Export[
"C:\\Users\\Sjoerd\\Desktop\\tabel.txt",
{#, CountryData[#, "GDP"]} & /@ CountryData["G8"],
"Table",
"FieldSeparators" -> " "
]
Run Code Online (Sandbox Code Playgroud)
用适合您情况的内容替换上面的文件路径.