fbpx

How to have DotNET CSharp client call Matlab script

(Last Updated On: October 8, 2015)

How to have DotNET CSharp client call Matlab script

Links are below for lessons mentioned in video

Join my FREE newsletter to learn more about this tech combo for automated trading 

C# Source code:

//mathworks.com/help/matlab/matlab_external/call-matlab-function-from-c-client.html
//add MLApp.dll with stackoverflow.com/questions/9780805/where-is-matlab-application-type-library
//or use how-i-fixed-it.blogspot.ca/2013/05/matlab-application-type-library-mlapp.html
//How-i-fixed-it:
//1. Open a windows command prompt as administrator
//2. Navigate to your Matlab installation directory\bin
//3. matlab.exe /register
//4. In the matlab command windows enter: !matlab -regserver
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CSharpCallMatlab
{
class Program
{
static void Main(string[] args)
{

// Create the MATLAB instance
MLApp.MLApp matlab = new MLApp.MLApp();

// Change to the directory where the function is located
matlab.Execute(@”cd C:\Users\Bryan\Documents\MATLAB\csharp”);

// Define the output
object result = null;

// Call the MATLAB function myfunc
matlab.Feval(“myfunc”, 2, out result, 3.14, 42.0, “world”);

// Display result
object[] res = result as object[];

Console.WriteLine(res[0]);
Console.WriteLine(res[1]);
Console.ReadLine();
}
}
}

NOTE I now post my TRADING ALERTS into my personal FACEBOOK ACCOUNT and TWITTER. Don't worry as I don't post stupid cat videos or what I eat!

Subscribe For Latest Updates

Sign up to best of business news, informed analysis and opinions on what matters to you.
Invalid email address
We promise not to spam you. You can unsubscribe at any time.

NOTE!

Check NEW site on stock forex and ETF analysis and automation

Scroll to Top