Total Pageviews

Blog Archive

Teaching (237) Mathematica (155) 3Q (48) Excel (45) SPSS (32) Cat (24) LaTeX (23) Mac (22) 君達呀 (15) Kaohsiung (14) 論文測試 (13) Mathematica教學講義 (3)

 

Followers

Mathematica 教學 修改CSV格式並轉檔

Chung-Yuan Dye 於 Friday, December 2, 2011 8:06 AM 發表



(*設定資料目錄*)
SetDirectory["~/Downloads"];
(*抓出所有的資料檔名*)
file = FileNames["*.txt"];
(*轉檔程式*)
recode[filename_String] := Block[{fn = filename, str},
(*讀入資料行,將文字轉成表達式,最後取出數字的元素*)
str = Cases[ToExpression@Import[fn, "Words"], _?NumberQ];
(*將資料依序輸出到xxx_new.txt檔*)
Do[str[[i]] >>> fn <> "_new.txt", {i, Length@str}]
]
(*將整個目錄的檔案轉檔*)
recode/@file
Tags:

讀者回應 ( 0 意見 )

Post a Comment

Please leave your name and tell me what you thought about this site. Comments, suggestions and views are welcomed.

如果這篇文章對你有幫助,那請留個訊息給我~