我正在使用组织模式为我的学校撰写报告。这非常方便,因为我可以在同一个文件中包含一些 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
要使用外部函数,您将需要使用tangle,例如首先,定义您的函数。
#+BEGIN_SRC matlab :tangle myfunc.m
function myfunc
disp('External function')
end
#+END_SRC
下一个 block 将 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
关于matlab - 如何在组织模式下在同一文件中定义matlab函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36727690/