matlab打包dll
1、matlab示例程序:
function untitled4(x)
z = peaks(x);
figure
surf(z)
end
2、輸入deploytool打包matlab程序,具體如下:
?3、拷貝
打包成功后,將生成for_redistribution_files_only文件夾中的dll文件拷貝到C#程序lib文件夾下,若沒(méi)有,新創(chuàng)建一個(gè)。
錯(cuò)誤解決:
解決方法:將matlab程序改寫(xiě)成一個(gè)方法。
C#調(diào)用dll
1、添加引用
?MWArray.dll在matlab安裝目錄..\matlab\toolbox\dotnetbuilder\bin\win64\v4.0下,untitled4.ll與untitled4Native.dll在C#工程lib文件夾下。
2、導(dǎo)入包
using untitled4;
using MathWorks.MATLAB.NET.Arrays;
3、添加button點(diǎn)擊事件
private void Button1_Click(object sender, EventArgs e)
{
untitled4.Class1 p3 = new untitled4.Class1();
p3.untitled4((MWArray)25);
}
完整示例代碼:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using untitled4;
using MathWorks.MATLAB.NET.Arrays;
namespace test1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void Button1_Click(object sender, EventArgs e)
{
untitled4.Class1 p3 = new untitled4.Class1();
p3.untitled4((MWArray)25);
}
}
}
?錯(cuò)誤解決1:
解決方法:debug平臺(tái)改為×64位
?
?錯(cuò)誤解決2:
解決方法:matlab程序返回一個(gè)數(shù),而C#代碼接收的是MWArray數(shù)據(jù)。
p3.untitled4((MWArray)25);
?
運(yùn)行結(jié)果:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-733089.html
?文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-733089.html
到了這里,關(guān)于【C#-1】C#調(diào)用matlab生成的dll庫(kù)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!