aspnet生成matlab图在web上显示

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

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


https://i-blog.csdnimg.cn/blog_migrate/ec4890ffcdb4f24479bdbe2f6abe87d9.jpeg

3】在deployment tool中做如下操作

https://i-blog.csdnimg.cn/blog_migrate/6196ee5453e00fb7f6211df1cff22d04.jpeg

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);

}

运行结果

https://i-blog.csdnimg.cn/blog_migrate/85e2d0d6e380cb16560e6ab1365b810f.jpeg

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

https://i-blog.csdnimg.cn/blog_migrate/47a6a830da8191a57710ad6b33eb7366.jpeg
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值