Re: [問題] 自動載入及自動存檔

看板Mathematica作者 (-858993460)時間12年前 (2011/10/17 15:49), 編輯推噓3(303)
留言6則, 1人參與, 最新討論串2/4 (看更多)
※ 引述《oversky0 (oversky0)》之銘言: : 兩個問題請教 : 1.我有一些自定函數想要每次開新的 .nb 就自行載入, : 請問有類似 dos 下 autoexec.bat 的功能嗎? 首先 Mathematica 裡有兩個目錄是可以放啟動內容的: $BaseDirectory systemwide base directory for files to be loaded by Mathematica $UserBaseDirectory user-specific base directory for files to be loaded by Mathematica 它裡面有幾個不同功能的資料夾: Applications Mathematica application packages Autoload packages to be autoloaded on startup FrontEnd front end initialization files Kernel kernel initialization files Licensing license management files SystemFiles general system files 我們要的就是在其中的 Kernel 資料夾裡放入啟動指令: Kernel/init.m run when the kernel is started Kernel/end.m run when the kernel is terminated 也就是說 你只要在 Kernel/init.m 裡放入指令 那每次啟動核心時就會自動執行其中的內容 (以上內容節錄改寫自 tutorial/MathematicaFileOrganization) 我自己是在 $BaseDirectory/Kernel/init.m 裡放了一行 << 引入一個放在我自己方便修改的資料夾的 .m (不然每次都要開 $BaseDirectory 有點煩...) 裡面放了不少我自己寫的捷徑函式方便我自己使用 : 2. .nb 檔會把計算的結果和圖都存起來, : 不過這樣不方便用 winmerge 這一類的 diff 程式來比較程式碼。 : 最近發現存成 .m 檔就只有存程式碼, : 不過每次要另外再另存新檔後再 load .nb 有點麻煩, : 有沒有辦法只按一次 Ctrl+S,就同時存 .nb 和 .m 兩種格式? 有一個大概在你的意料之外的功能有你要的效果: Initialization Cell 如果一個格子被設為 Initialization Cell 則當你在剛打開這個 .nb 然後執行某個格子時 它會問你要不要先執行 Initialization Cell 要的話就會先把這個 .nb 裡的所有 Initialization Cell 執行一遍再做事 在你設定 Initialization Cell 之後第一次存檔時 Mathematica 會問你要不要做一個 .m 的 package 選是的話所有 Initialization Cell 的內容就會被存進那個 .m 檔裡 之後每次存檔都會更新 這樣你就可以獨立 << 進來那個 .m 來執行那些內容 雖然這個功能的目的不是單純多另存 .m 但它的確是可以達到你要的效果就是了... -- ˊ_▂▃▄▂_ˋ. ◣          ▅▅ ▅▅ ι●╮   ./◤_▂▃▄▂_◥ \'▊   HARUHI █████ <■┘   ◤◤◥█◥◥█Δ   ISM    By-gamejye ¢|\   ▌▌ζ(▏●‵◥′●)Ψ ▏           █    ⊿Δ    /|▋ |\ ▎         ハルヒ主義      ▄█ ◥◥|◣ ‵′ ◢/'◢◢S.O.S 世界をいに盛り上げるための宮ハルヒの    -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.30.130 ※ 編輯: LPH66 來自: 140.112.28.92 (10/18 07:48)

10/18 10:30, , 1F
謝謝 LPH66 詳細的說明。這篇可以請版主 M 起來嗎?
10/18 10:30, 1F

10/18 10:51, , 2F
我在 kernel 內沒找到 init.m 。不過在 Kernel\Packages\
10/18 10:51, 2F

10/18 10:52, , 3F
有找到。看這個目錄下 ReadMe.txt 應該是這個沒錯。
10/18 10:52, 3F

10/18 11:43, , 4F
第二個問題我試的結果是要在 option inspector 內將
10/18 11:43, 4F

10/18 11:45, , 5F
AutoGeneraterdPackage 設為 auto 或 manual
10/18 11:45, 5F

10/18 11:46, , 6F
我安裝後的預設值是 None,要改一下才行。
10/18 11:46, 6F
文章代碼(AID): #1Eczu8YC (Mathematica)
討論串 (同標題文章)
文章代碼(AID): #1Eczu8YC (Mathematica)