Open AljenU opened 2 years ago
Part of this workflow can maybe be replaced with a piggyback on an existing neuron stdout redirection for python. That shold be looked into first.
I have tried to use mex functionality by giving generateLibraryDefinition the argument IncludePath=fullfile(matlabroot, "extern", "include").
If I then try to import "mex.h" (for using mexPrintf), I get the error: error: Using MATLAB Data API with C Matrix API is not supported.
Importing "mex.hpp" and "mexAdapter.hpp" gives:
Ah, for the c++ version, we should indeed do the c++ version, which is calling fprintf in the matlab session, according to https://nl.mathworks.com/help/matlab/matlab_external/displaying-output-in-matlab-command-window.html
So, we are actually doing something like https://nl.mathworks.com/help/matlab/getting-started-with-matlab-engine-api-for-c.html, which means we have different headers that should be included, #include "MatlabEngine.hpp" and #include "MatlabDataArray.hpp". Thus also different include and library paths are involved, as per https://nl.mathworks.com/help/matlab/matlab_external/build-c-engine-programs.html
Thus, we would have a 'global' variable for the pointer to the matlab engine, need to find the engine once, then in the custom stream print function do the same as in the displayOnMATLAB function in the beforementioned displaying-output example.
For now, would keep the input only as string. Later, might want to differentiate between stdout and stderr. Will have to do something slightly different for the std::vector
First (unsuccessful) try on a new branch exploration_connect_MATLAB_session: https://github.com/edovanveen/matlabneuroninterface/tree/exploration_connect_MATLAB_session
Instead of redirecting to file, it is probably possible to redirect to the matlab command window.
We would need to connect to matlab from c(++) code: https://nl.mathworks.com/help/matlab/apiref/matlab.engine.connectmatlab.html Redirect the output streams in the c code (many stackoverflow questions) And make it so the redirected stream is shown in the command window: https://nl.mathworks.com/help/matlab/matlab_external/displaying-output-in-matlab-command-window.html Where instead of explicit call to displayOnMATLAB, that should be wrapped in the streambuf sync.