How can I interact with MATLAB from my CSharp code, and can I connect to an existing MATLAB session?

10 views (last 30 days)
I have a C# application and I want to execute MATLAB functions from it and pass data between my C# application and MATLAB. How can I do that? Can I connect to an existing MATLAB session?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Jan 2024
You can interact with MATLAB from C# code either using using MATLAB as a COM Automation server or by using MATLAB Engine API.
MATLAB Engine API
It is recommended that you use the MATLAB Engine API for .NET to call a MATLAB function from a C# application in MATLAB R2022b or later.
  • For C# example code, see the following link:  https://www.mathworks.com/help/matlab/matlab_external/execute-matlab-functions-from-net.html
  • See the following link for more information on how to connect to an existing MATLAB session or start a new session:  https://www.mathworks.com/help/matlab/apiref/mathworks.matlab.engine.matlabengine.html
MATLAB as a COM Automation Server
  • For C# example code, see the following link:  https://www.mathworks.com/help/matlab/matlab_external/call-matlab-function-from-c-client.html
  • See the following link for more information on how to connect to an existing MATLAB session or start a new session:    https://www.mathworks.com/help/matlab/matlab_external/creating-the-matlab-server.html
 

More Answers (0)

Products


Release

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!