How to write MATLAB functions in Jupyter Notebook?
总览
我在Jupyter Notebook中使用MATLAB内核。 我想在笔记本中编写一个函数,而不是引用保存在另一个
Error: Function definitions are not permitted in this context.
视觉示例:
在一个新的笔记本中,如下图所示:
现在,如果我创建一个新的
然后通过笔记本调用then函数:
但这很不方便。 有没有一种方法可以直接从Jupyter Notebook内部定义功能?
我的软件
- MATLAB 2017b
- Windows 10
- 在Chrome中运行的Jupyter
- 通过Python安装的Jupyter
文档表明您可以使用魔术:
1 | %%file name_of_your_function.m |
以您的示例为例,您的单元格应编写如下:
1 2 3 4 5 | %%file fun.m function out = fun(in) out = in + 1; end |
这将创建一个名为