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
284 stars 36 forks source link

import local package in jupyter notebook #51

Closed zguo235 closed 1 year ago

zguo235 commented 1 year ago

Thank you for your efforts in this great package. My problem is that I have a local package and I want to import it like this:

>> javaaddpath('./lib/javaplex.jar');
>> import edu.stanford.math.plex4.*;
>> api.Plex4.createExplicitSimplexStream() 
ans = edu.stanford.math.plex4.streams.impl.ExplicitSimplexStream@513fd4

This code works in the command line in linux. In Jupyter notebook, the output is like this:

>> api.Plex4.createExplicitSimplexStream() 
Unable to resolve the name 'api.Plex4.createExplicitSimplexStream'.

I am not sure if this issue is due to this jupyter-matlab-proxy, but I still want to find some solution to import local package in jupyter notebook.

rashedmyt commented 1 year ago

Hi @zguo235

Thank you for trying out MATLAB Integration for Jupyter.

I was able to reproduce the issue you are facing when the import statement and the java function call are in different code cells.

You can fix this by placing both the import statement and the necessary java code in a single code cell.

Currently we do not support having the import statement and the function call in different code cells as each code cell is treated as a separate MATLAB script file.

Hope this helps!

zguo235 commented 1 year ago

Thank you for the solution and clear explanation for this problem. If possible, can you add an enhancement tag to this issue, as I think using functions which are imported in other cells is a very normal situation in jupyter notebook.