This script shows how C# functions/classes and forms (gui) can be used in Matlab.
The zip contains:
- a example c# class (ComMatlab.cs) with different inputs and outputs functions.
- a info_ComMatlab.txt with the commands how to compile and register a c# activex control
- a ComMatlabtest.m for testing the c# functions.
- a example c# class (MatlabGUI.cs) which creates a form for user input (uses the other MatlabGUI cs files)
- a info_MatlabGUI.txt with the commands how to compile and register a c# activex control from multiple .cs files
- a MatlabGUItest.m for testing the c# userinput Form
(The MatlabGUI Form is designed with Visual Studio 2005)
I was wondering if there's any newer version of this process available.
It doesn't seem to work for me, mainly because of the lack of my knowledge on how to compensate for the differences of MATLAB 2015b vs 2007b as well as the differences in Visual Studio between 2007 and 2016.
For 64-bit OS, use the regasm resides C:\Windows\Microsoft.NET\Framework64\v4.0.30319 folder
I tried to configure MSVC to compile the dll (used File->New->Project->CisualC#->Class Library) and got the error
??? Error using ==> actxserver at 91
Server creation failed. Invalid ProgID 'ComMatlab.ComMatlabClass'
Error in ==> ComMatlabtest at 7
net = actxserver('ComMatlab.ComMatlabClass'); % Load the ActiveX ComMatlab
I traced it down to a project properties setting under "Application" where you must select the "Assembly Information" button and then select the "Make assembly COM-Visible" checkbox.
Dear Dirk-Jan Kroon,
I found my pb, the code works fine now. The pb was that I did not subscribe to COM Interop in the project properties.
Thanks again for this very useful post.
Dear Dirk-Jan Kroon,
Thanks for your post. Compiling is ok but when I try to use in Matlab, i got following error :
>> net = actxserver('MatlabGUI.FormControlClass');
??? Error using ==> feval
Server Creation Failed: Le fichier spécifié est introuvable.
If you could help, would be nice. Thanks
Added C# code and matlab files for creation of a C# form for user input.
And also renamed files to more logical names