matlab - 如何在组织模式下在同一文件中定义matlab函数

标签 matlab emacs org-mode

我正在使用组织模式为我的学校撰写报告。这非常方便,因为我可以在同一个文件中包含一些 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/

相关文章:

matlab - 在matlab中将包含二进制数据的文本文件读取为单个矩阵

matlab - MATLAB gui 中的法语口音

Emacs 组织模式 : textual reference to a file:line

html - 将 Org 模式文件导出为 HTML 后的意外链接行为

bash - 我如何在 org babel 中加载 bash(而不是 sh)以启用 #+BEGIN_SRC bash?

matlab - 将曲线拟合到 Matlab 中具有特定颜色的区域

matlab - 如何在 MATLAB 中连接多维数组?

emacs - 我应该将 Emacs Lisp 中的 add-to-list 称为破坏性函数吗?

org-mode - orgmode - 更改代码块背景颜色

emacs - 组织模式。在列 View 中排序