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