aspnet生成matlab图在web上显示

来源:互联网 发布:明朝为什么会灭亡 知乎 编辑:程序博客网 时间:2024/06/06 21:21

1MATLAB命令窗口输入mbuild-setupmex-setup,都选择MicrosoftVisual/c/c++ version7.1 in "ptah loation"\Microsoft Visualstudio.NET[2010]选项。其中ptahloationvs.net的路径名。每一个命令的输入顺序大概是y;[0,1,2,3..];y

2matlab命令窗口输入deploytool:得到下图,按下图设置好。


http://hiphotos.baidu.com/fendouzlin/pic/item/f7acdb789f233fb32f73b3c9.jpg

3】在deployment tool中做如下操作

http://hiphotos.baidu.com/fendouzlin/pic/item/38e0e42104e72310935807ad.jpg

4】找到【3】生成的DLL文件:我的在E:\Code\MATLAB\BP_sample\distrib\[BP_sample.dll]

5】打开VS新建webform.添加引用

引用1:第【4】步生成的DLL文件

引用2MWArray.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);

}

运行结果

http://hiphotos.baidu.com/fendouzlin/pic/item/89683c024161b84f738b65b2.jpg

附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那样的弹出窗口。效果图如下:

http://hiphotos.baidu.com/fendouzlin/pic/item/c92d4403185c18581c95830e.jpg
0 0
原创粉丝点击