【1】MATLAB命令窗口输入mbuild-setup和mex-setup,都选择MicrosoftVisual/c/c++ version7.1 in "ptah loation"\Microsoft Visualstudio.NET[2010]选项。其中ptahloation为vs.net的路径名。每一个命令的输入顺序大概是y;[0,1,2,3..];y
【2】 matlab命令窗口输入deploytool:得到下图,按下图设置好。
【3】在deployment tool中做如下操作
【4】找到【3】生成的DLL文件:我的在E:\Code\MATLAB\BP_sample\distrib\[BP_sample.dll]
【5】打开VS 新建webform.添加引用
引用1:第【4】步生成的DLL文件
引用2:MWArray.dll【我已发给你,或者在D:\ProgramFiles\MATLAB\R2010b\toolbox\dotnetbuilder\bin\win32\v2.0找到】
【6】在webfrom.cs 添加using
usingUntitled1;[第5步中的引用1名]
usingMathWorks.MATLAB.NET.Arrays;
usingMathWorks.MATLAB.NET.Utility;
【7】
protectedvoidPage_Load(object sender,EventArgse)
{
try
{
test_cs_calsstt =null;
MWNumericArrayinput1 =null; //输入参数
MWNumericArrayinput2 =null;
MWNumericArrayoutput =null; //输出参数
MWArray[]result =null; //结果
tt =newtest_cs_calss();//实例化
input1 = 5;input2 = 5;
// result =tt.test_cs(1, input1,input2);
tt.test_cs(input1,input2);
}
运行结果
附matlab编写的*.m 文件如下:
function test_cs(h,D)
hold on;
for x=-10:0.1:10
if x > D
y=h;
plot(x,y)
else if x < -D
y=-h;
plot(x,y);
else
y=h/(D*x);
plot(x,y)
end
end
end
承接matlab和asp.net混合编程-matlab生成图在web上显示(一),matlab分析生成的图不能直接嵌入到web页面进行修改。
不说太多,直接看代码。
修改后*.m如文件如下:
function test_cs(h,D,path)
hold on;
for x=-10:0.1:10
if x > D
y=h;
plot(x,y)
else if x < -D
y=-h;
plot(x,y);
else
y=h/(D*x);
plot(x,y);
set(gcf,'visible','off');//设置matlab生成的图片窗口不再浏览器上弹出来,其中gcf为窗口句柄
print(gcf,'-djpeg',path); //把matlab生成的图片存放的指定(path)位置
end
end
end
asp.net后代代码如下:程序比较简单。我就不再注释了。
protected void Button1_Click(object sender, EventArgs e)
{
Random rd = new Random();
string fileName = rd.Next(10, 99) + ".jpg";
matlabtest_cs tt = new matlabtest_cs();
MWNumericArray input1 = 4;
MWNumericArray input2 = 5;
string savePath = Server.MapPath("~/images");
if (!Directory.Exists(savePath))
{
Directory.CreateDirectory(savePath);
}
MWCharArray path = savePath + "\\" + fileName;
tt.test_cs(input1, input2, path);
Image1.Width = 800;
Image1.Height = 800;
Image1.ImageUrl = "~/images/" + fileName;
Image1.Visible = true;
}
效果就是matlab生成的图片可以在<image>控件中显示,而不是像alert那样的弹出窗口。效果图如下: