I feel at home in C# and I’ll design a console application that will fetch some data from a web service. I’d like to allow a group of scientists to use the data in MatLab. One way to achieve that is to store it in a file on the HDD and then load the contents of it into MatLab.
That got me thinking, though. Is it possible to create a function in MatLab that calls an EXE created in C# so my scientific friends can go:
a = GetMeSomeData()
and populate the variable a with the response of the service? (I would, of course, format the data using my C# code so it’ll fit the matrix model of MatLab.)
I’ve done some googling before I start working on this but most of the stuff I’ve found is about an old version of MatLab (2007) and it’s said something about creating a COM object.
You can easily call functions in a .NET assembly. First you have to tell Matlab what assembly you are going to use:
After that, you just call functions in your m-files:
You can even have multiple outputs. A C# function like this:
can be called like this in Matlab: