mathworks / jupyter-matlab-proxy

MATLAB Integration for Jupyter enables you to run MATLAB code in Jupyter Notebooks and other Jupyter environments. You can also open MATLAB in a browser directly from your Jupyter environment to use more MATLAB features.
Other
251 stars 34 forks source link

add custom path and command when matlab kernel starts #36

Open utotch opened 1 year ago

utotch commented 1 year ago

I tried to locate pathdef.m to notebook root or userpath of matlab but that doesn't affect to change path of the matlab kernel.

How can I automatically add custom path to a matlab kernel when the kernel starts?

rashedmyt commented 1 year ago

Hi @utotch

I see that you want to add custom path and command automatically when the MATLAB Kernel starts.

You can modify the startup script to run the MATLAB commands which add custom paths and commands when MATLAB starts.

Hope this helps.

utotch commented 1 year ago

Thanks for the comment @rashedmyt. I tried to add path in startup.m by using "addpath" function. But unfortunately, the path was not added even though I reboot kernel and jupyterlab.

I think startup and pathdef loading spec is unclear and undocumented for Matlab kernel.

rashedmyt commented 1 year ago

Hi @utotch

Thank you for the response.

  1. Currently, we do not have an inbuilt solution to running custom commands on kernel start. I have notified the development teams of this feature, and we will consider this for a future release of the jupyter-matlab-proxy package.

    How can I automatically add custom path to a matlab kernel when the kernel starts?

  2. Please note that, when a kernel is starts up, it does not necessarily launch MATLAB. It may connect to an previously started MATLAB process. The architecture section of the README gives more information about the lifecycle of MATLAB and its relation to kernels. This information may help understand when the "MATLAB startup" scripts run wrt MATLAB kernels.

  3. Code executed from a notebook should behave the same way as it would have when run directly in MATLAB. I suspect there might be more going on with your particular environment. To help troubleshoot these issues related to the startup and pathdef would you please run this notebook and share the results?

prabhakk-mw commented 2 months ago

@utotch ,@rashedmyt

Does the environment variable MWI_MATLAB_STARTUP_SCRIPT from Advanced-Usage.md help this usecase?