📄 example.cs
字号:
using System;
using System.Runtime.InteropServices;
using UtilityMatlabCompilerVer4 ;
namespace MatlabCSharpExample
{
class Example
{
//constructor
public Example()
{
mypluslibInitialize();
}
public void CleanUp()
{
mypluslibTerminate();
}
/* declare dll functions */
[ DllImport( "mypluslib.dll ", CallingConvention = CallingConvention.Cdecl)]
public static extern void mypluslibInitialize();
[ DllImport( "mypluslib.dll ", CallingConvention = CallingConvention.Cdecl)]
public static extern void mypluslibTerminate();
[ DllImport( "mypluslib.dll ", CallingConvention = CallingConvention.Cdecl)]
public static extern void mlfMyplus(int nargout, ref IntPtr y, IntPtr a, IntPtr b);
/* end dll functions */
[STAThread]
static void Main(string[] args)
{
Console.WriteLine(" ") ;
Example obj = new Example() ;
Console.WriteLine("Generating a C Shared Library from MATLAB M-Files " ) ;
Console.Write("\n") ;
double c = obj.CalculatePlus(2.1, 3.4) ;
Console.WriteLine(c.ToString() ) ;
obj.CleanUp() ;
}
public double CalculatePlus(double a, double b)
{
/* declare mxArray variables */
IntPtr mx_a = (IntPtr) null ;
IntPtr mx_b = (IntPtr) null ;
IntPtr mx_y = (IntPtr) null ;
/* convert Cs double to mxArray */
mx_a = MatlabCSharp.double2mxArray_scalarReal(a) ;
mx_b = MatlabCSharp.double2mxArray_scalarReal(b) ;
/* call the implemental function */
mlfMyplus(1, ref mx_y, mx_a, mx_b);
/* convert back mxArray to Cs double */
double result = MatlabCSharp.mxArray2double_scalarReal(mx_y) ;
return result ;
}
} // end class
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -