Package: imatlab
InstallationUseInline graphicsPlotly exporterStatic exportersCustom exportersEnvironment variablesAsynchronous outputMATLAB debuggerDifferences with the Calysto MATLAB KernelTestsThis kernel requiresJupyterwith Python 3.5+, and theMATLAB engine for
PythonR2016b+ (this release provides a much better completion API), which
needs to be installed first.  Note that additionally, Python versions not
supported by the engine are likewise not supported by the kernel.InstallationAs usual, install using pip:$pipinstallimatlab# from PyPI$pipinstallgit+https://github.com/imatlab/imatlab# from GithubThen, register the kernelspec with$python-mimatlabinstallIn the absence of administrator rights, the--userflag should be added to
all of these commands.Use# Notebook (in the notebook interface, select Matlab from the 'New' menu):$jupyternotebook# or QtConsole:$jupyterqtconsole--kernelimatlab# or terminal:$jupyterconsole--kernelimatlabInline graphicsMATLAB figures can be displayed in native MATLAB windows (the default), or
(when using the notebook) as inline images.  The kernel can natively display
static images, or usePlotlyto generate interactive
JavaScript figures.The exporter is set by calling theimatlab_export_figfunction, which is
automatically added to the MATLAB path when the kernel is running.  The
following settings are possible:imatlab_export_fig('')% Native windows.imatlab_export_fig('fig2plotly')% Plotly figures.imatlab_export_fig('print-png')% Static png figures.imatlab_export_fig('print-svg')% Static svg figures.imatlab_export_fig('print-jpeg')% Static jpeg figures.This call must be issued before the first figure is shown.  Note that the
non-native exporters will callset(0, 'defaultfigurevisible', 'off')to
prevent the window from being briefly displayed, whereas using native windows
turns the default figure visibility back'on'.Plotly exporterTo use Plotly inline graphics in the notebook, thePlotly MATLAB API(>=2.2.7) must be installed, as follows:Cloneplotly/MATLAB-Onlineor download it as azip file.Recursively add the resulting extracted folders to the MATLAB search path
usingaddpath(genpath(<PlotlyMATLAB APIpath>));.  Either put such a
call in yourstartup.m, or then callsavepath;to save the path.In MATLAB, copy the required JavaScript files and initialize the
credentials:getplotlyoffline('https://cdn.plot.ly/plotly-latest.min.js');try,signin;catch,saveplotlycredentials('','');end;(If your version of MATLAB uses an old OpenSSL, you may need to use HTTP
instead of HTTPS.)At the beginning of each notebook, you may then callimatlab_export_fig('fig2plotly')to use automatically Plotly inline
graphics (no further calls to the Plotly API are required; in particular,
ignore the output fromgetplotlyoffline).Static exportersThe static exporters (png, svg, and jpeg) do not required additional
dependencies.The default size of exported figures, as well as whether to display figures
before exporting them, should be set using standard figure properties (set(0, 'defaultpaperposition', [left, bottom, width,height]);, etc.).Custom exportersFor further customization, you may override theimatlab_export_figfunction
(the default version is provided byimatlaband added to the MATLAB path).
This function is called with no arguments after each notebook cell is executed,
while the current directory is temporarily switched to a temporary folder; this
function should return a cell array of filenames with.html,.png, or.jpg/.jpegextension.  The corresponding files, which should have been
created by the function, will be loaded into the notebook.Environment variablesIMATLAB_CONNECTIf this environment variable is set to a valid MATLAB identifier, the kernel
will attempt to connect to the shared engine with that name.  If it is set
to another non-empty value, it will connect to any existing shared engine.IMATLAB_CDIf this environment variable is set, the engine’s working directory will be
changed to match the kernel’s working directory.IMATLAB_CONNECTneeds to be set outside of MATLAB (as it is checked before
the connection to the engine is made).  Other environment variables can be set
either outside of MATLAB (before starting the kernel) or from within MATLAB
(usingsetenv).Asynchronous outputA construct such as1, pause(1), 2will output1and2with a one
second interval on Linux and OSX, but together after a one second wait on
Windows.  PRs improving Windows support are welcome.Asynchronous output usingtimerobjects seem to be completely unsupported
by the MATLAB engine for Python.MATLAB debuggerThe MATLAB debugger is cleared (dbclear all) before each execution, as
interactive input is not supported by the engine API.Differences with the Calysto MATLAB KernelThe completion system is much more robust, by relying on the new API
available in MATLAB 2016b.History is read from and written to MATLAB’s ownHistory.xml, and thus
shared with standard MATLAB sessions.  Note that if the file does not exist
(e.g. if thedon’t save history fileoption is set, or in a console-only
setup), history will not be reloaded into later sessions.  (A PR for loadinghistory.minstead would be welcome; it would need to properly parse
multiline inputs in that file.)Synchronous output is supported on Linux and OSX (see above).There is no magics systems, as MATLAB already provides many functions for
this purpose (cd,edit, etc.).Inline graphics can be based onplotly, and thus interactive.TestsRun tests withpython-munittestorpytestafter installing the kernel andjupyter_kernel_test.