Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String Mathematica-将字符串的元素分隔为列?_String_List_Wolfram Mathematica - Fatal编程技术网

String Mathematica-将字符串的元素分隔为列?

String Mathematica-将字符串的元素分隔为列?,string,list,wolfram-mathematica,String,List,Wolfram Mathematica,我正在生成编码输出,这是一个字符串列表,看起来像列表。有没有办法将它们转换成实际的列表,这样我就可以选择元素并将它们格式化为列?还是在字符串中选择字符并将其放入列中的方法 Button[ "Run", {afit = Input["Please Enter ID#", deleteme] ; ClearAll[dat], dat := TraumaEncoding@afit; ClearAll[funcel], funcel[p_String]

我正在生成编码输出,这是一个字符串列表,看起来像列表。有没有办法将它们转换成实际的列表,这样我就可以选择元素并将它们格式化为列?还是在字符串中选择字符并将其放入列中的方法

  Button[
    "Run",
    {afit = Input["Please Enter ID#", deleteme] ;
    ClearAll[dat],
    dat := TraumaEncoding@afit;
    ClearAll[funcel],
    funcel[p_String] :=
     Which[StringMatchQ[
      p, ("*no new ones*" | "*no new marks*" | 
      "*old wounds healing*"), 
      IgnoreCase -> True], "0",
      StringMatchQ[p, ("*abrasion*"), IgnoreCase -> True], "{1,0}",
      StringMatchQ[p, ("*lacer*"), IgnoreCase -> True], "{1,1}",
      StringMatchQ[p, ("*punct*") | ("*pct*"), 
      IgnoreCase -> True], "{1,2}",
      StringMatchQ[p, ("*amput*"), IgnoreCase -> True], "{1,4}",
      StringMatchQ[
       p, ("*wound*" | "*injur*" | "*trauma*" | 
       "*swollen*" | "*swell*"), IgnoreCase -> True], 1, True, 0];
    funcel[___] := 0;
    ClearAll[func],
    func[l_List] := 
     Which[MemberQ[Map[funcel, l], "0"], "0", 
      MemberQ[Map[funcel, l], "{1,4}"], "{1,4}", 
      MemberQ[Map[funcel, l], "{1,2}"], "{1,2}", 
      MemberQ[Map[funcel, l], "{1,1}"], "{1,1}", 
      MemberQ[Map[funcel, l], "1-0"], "1,0", MemberQ[Map[funcel, l], 1],
       1, True, 0];
    listo := Map[func, dat]},
  Background -> Yellow, Sequence @@ $ButtonOptions
  ]
产生如下结果:

   {"{1,2}", "{1,2}", "0", "{1,2}", "0", "0", "0", "0", "0"}
我需要将其转换为类似的内容,理想情况下,我可以将其导出到Excel文件:

    Header  Header
      1       2
      1       2
      0
      1       2
      0
     etc.,
或整个列表:

data =
 Prepend[ToExpression /@ {"{1,2}", "{1,2}", "0", "{1,2}", "0", "0", 
    "0", "0", "0"}, {"header1", "header2"}]

(* ==> {{"header1", "header2"}, {1, 2}, {1, 2}, 0, {1 2}, 0, 0, 0, 0, 0}   *)
格式化为表格:

出口:

Export["filename.csv", data]

一个小提示:实际上,您不需要将映射
来表达
到列表中,相反,您可以应用它

In[91]:= ToExpression@{"{1,2}","{1,2}","0","{1,2}","0","0","0","0","0"}
Out[91]= {{1,2},{1,2},0,{1,2},0,0,0,0,0}

谢谢:D我会很快测试,然后选择你的答案!陛下这是不对的。你知道为什么吗?你是导出到xls还是csv?xls的问题在于,您的表不是列表的矩形列表。CSV在那里工作得更好。如果要使用PadRight,请注意该表是矩形的(并使“0”输出成为一个列表,最好是{“0”,“0”})。顺便说一句,为什么不让函数直接输出列表呢。你为什么需要绳子?哦!谢谢你:我想这会快一点。它可以为我导出:在[92]:=data=ToExpression@{{1,2}、{1,2}、{0}、{1,2}、{0}、{1,2}、{0,0}、{1,2}、{1,2}、{0,0,0}、{0,0}、{1,2}在[94]:=file=ToFileName[$temporalyname}、.csv]目录中导出[92]={1,2}、{1,2}、{1,2}、{1,2}、{1,2}、{0,0,0,0,0}、{0,0}、{0,0}、{0}、{0}文件名,0}在[94]:=tmp.csv][96]:=FilePrint[file]在[96]中的求值期间::=1,2 1,2 0 1,2 0 0 0
In[91]:= ToExpression@{"{1,2}","{1,2}","0","{1,2}","0","0","0","0","0"}
Out[91]= {{1,2},{1,2},0,{1,2},0,0,0,0,0}