I am trying to export a .dll (.Net Assembly) using Matlab R2013a (8.1.0.604) with a simple add function which adds two numbers and trying to use this .dll file in visual studio 2013 for c#. I have added the reference to the .dll files for Matlabtest.dll and MWArray.dll. Now while I am trying to make the object of the Class "Adding" (the name of class from Matlabtest.dll) visual studio stops working without any error and unable to make the object of class. Please suggest me any solution with some reference code etc. What step i am missing need suggestions and help.
Here is my matlab function
function output = adding( a,b )output = a + b;end
Here is my C# code on a button click
using MathWorks.MATLAB.NET.Arrays;using MathWorks.MATLAB.NET.Utility;using MatlabTest;namespace TestingMatlab{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { private MatlabTest.Adding obj; public MainWindow() { InitializeComponent(); } private void btn_sum_Click(object sender, RoutedEventArgs e) { try { MWArray a; MWArray b; a = (MWArray)txt_num1.Text; b = (MWArray)txt_num2.Text; Adding obj = new Adding(); MWArray output = obj.adding((MWArray)a, (MWArray)b); Console.WriteLine(output.ToString()); } catch (Exception ex) { MessageBox.Show(ex.Message); } } } }
Best Answer