简体   繁体   English

具有Matlab内核的Jupyter Notebook

[英]Jupyter Notebook with Matlab kernel

I basically have a bunch of user-defined functions that I can run when I use Matlab, because I can specify the working directory. 基本上,我使用Matlab时可以运行一堆用户定义的函数,因为我可以指定工作目录。 However when I use Jupyter Notebook those functions are undefined. 但是,当我使用Jupyter Notebook时,这些功能是不确定的。 How do I specify the working directory in this case? 在这种情况下,如何指定工作目录?

Either a permanent solution or a session solution is OK. 永久解决方案或会话解决方案都可以。 However my preference is the session solution, so that I do not have to specify back the working directory all the time to its default value. 但是,我更喜欢会话解决方案,因此我不必一直将工作目录重新指定为其默认值。

You can use the function addpath to add a directory containing M-files to the MATLAB search path. 您可以使用函数addpath将包含M文件的目录添加到MATLAB搜索路径。

Some relevant links to documentation pages: 指向文档页面的一些相关链接:

If you are editing the functions, you can use bash script inside Jupyter notebook. 如果要编辑功能,则可以在Jupyter笔记本中使用bash脚本。 This way you can have your functions in front of you. 这样,您可以将自己的功能摆在面前。 With the example code below, they will be written down on the same path. 在下面的示例代码中,它们将被记录在同一路径上。 But you can save them anywhere at the end, again using %%shell . 但是您可以使用%%shell再次将它们保存在任何地方。

%%shell
echo "
y = func(x) ... % here you copy the function m file
" > func.m

Also you can implement the Amro's answer inside the notebook with %%shell . 您也可以使用%%shell在笔记本中实施Amro的答案。 This way you can have a session solution within the Jupyter notebook. 这样,您就可以在Jupyter笔记本中获得会话解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM