2
我正在使用組織模式爲我的學校編寫報告。這非常方便,因爲我可以在同一個文件中包含一些Matlab代碼。 然而,問題是我不能定義新的函數,因爲Matlab需要在單獨的文件中聲明函數。如何在組織模式下在同一文件中定義matlab功能
這非常不方便,因爲它阻止我只有一箇中心文件進行修改。
我正在使用組織模式爲我的學校編寫報告。這非常方便,因爲我可以在同一個文件中包含一些Matlab代碼。 然而,問題是我不能定義新的函數,因爲Matlab需要在單獨的文件中聲明函數。如何在組織模式下在同一文件中定義matlab功能
這非常不方便,因爲它阻止我只有一箇中心文件進行修改。
這適用於我使用嵌套函數。輸出有點醜陋,但這裏沒有創建文件,只是發送到Matlab的代碼塊。 (這適用於MacOSX和Linux,它不適用於Windows,不確定)。
#+BEGIN_SRC matlab
function parent
disp('This is the parent function')
nestedfx
function nestedfx
disp('This is the nested function')
end
end
#+END_SRC
#+RESULTS:
#+begin_example
< M A T L A B (R) >
Copyright 1984-2013 The MathWorks, Inc.
R2013a (8.1.0.604) 64-bit (maci64)
February 15, 2013
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
>> >> This is the parent function
>> >> >> >> This is the nested function
>> >> >> >>
#+end_example
要使用外部功能,您必須使用纏結,首先,定義你的功能。
#+BEGIN_SRC matlab :tangle myfunc.m
function myfunc
disp('External function')
end
#+END_SRC
這個下一塊把m文件弄亂了。
#+BEGIN_SRC emacs-lisp
(org-babel-tangle)
#+END_SRC
#+RESULTS:
| myfunc.m |
現在我們使用它的代碼塊
#+BEGIN_SRC matlab
myfunc()
#+END_SRC
#+RESULTS:
#+begin_example
< M A T L A B (R) >
Copyright 1984-2013 The MathWorks, Inc.
R2013a (8.1.0.604) 64-bit (maci64)
February 15, 2013
To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit www.mathworks.com.
>> External function
>>
#+end_example
這是不正確的。您可以在一個文件中有多個功能,但它們只是不能從外部訪問。他們被稱爲[本地功能](http://www.mathworks.com/help/matlab/matlab_prog/local-functions.html?refresh=true) – Suever
@Suever,你是對的,但最終我想避免創建一個新的文件在一起。也許在org模式下模擬一個新文件是要走的路? – maroxe