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 教學:表格自動取小數點及補零

Chung-Yuan Dye 於 Sunday, January 8, 2012 12:16 AM 發表

Mathematica可以將表格轉換成標準的LaTeX格式的表格。但是唯一的缺點是要自己條小數點,每次一個一個調整尤其是在每個欄位要求又不一樣時實在煩人。所以寫了以下這個函數,會根據指定的要求自動將小數點四捨五入或補零。懶得話,直接將程式加進init.m,每次程式打開會自動載入~~懶,的確是一種美德!
(*init.m路徑*)
$UserBaseDirectory <> "/Kernel/init.m"

data={{9549.26,9548.13,9549.12,0.351504,182.612,107.94},{9666.36,
9654.91,9665.92,2.17506,138.135,102.33},{8917.18,8917.18,
8917.18,1.45152*10^-7,75.7518,99.75},{8917.18,8917.18,8917.18,
1.22834*10^-10,340.693,472.25}};

mynumform[data_List,decimal_List]:=Block[{d=decimal,mydata=data},
Table[Map[NumberForm[#[[1]],{10,#[[2]]},
(*在-Infinity跟Infinity之間不用以指數形式表示*)
ExponentFunction->(If[-10^100<#<10^100,Null,#]&)]&,
Transpose@{mydata[[z]],d}],{z,Length@mydata}]
]

TableForm@mynumform[data, {2, 2, 2, 4, 3, 3}]
Tags: ,

讀者回應 ( 0 意見 )

Post a Comment

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

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