1.建一个m文件(test.m) 如
function test(h,D)
for x=-10:0.1:10,
if x>D
y=h;
hold on;
plot(x,y)
elseif x<-D
y=-h;
hold on;
plot(x,y)
else
y=h/(D*x);
hold on;
plot(x,y)
end
end
然后点Build-Com Object,就会在comtest\distrib\文件夹下生成一个test.dll(它就
是做好的com组件)。
3.c#下实现调用
新建一个c#项目(我采用的是vs.net2008),选中右边的解决方案资源管理器中的引用
,点鼠标右键,选添加引用,在弹出来的窗口中选com,然后也找到test .dll,点选
择,然后确定就可,此时此com组件也添加到工程里面去了。 还需要将MWArray.dll添加引用,
MWArray.dll在matlab\toolbox\donetbuilder\bin\win32\MWArray.dll
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MathWorks.MATLAB.NET.Arrays;
using MathWorks.MATLAB.NET.Utility;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
MWNumericArray m = 2.0;
MWNumericArray n = 1.0;
mytest.mytestclass ts = new mytest.mytestclass();
//test.testclass ts = new test.testclass();
//MWArray result = ts.test(f);
// ts.test((MWNumericArray) m, (MWNumericArray) n);
ts.test(m, n);
Console.ReadLine();