詳解C#調(diào)用matlab生成的dll庫
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文件夾下,若沒有,新創(chuàng)建一個。
錯誤解決:
解決方法:將matlab程序改寫成一個方法。
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點擊事件
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); } } }
錯誤解決1:
解決方法:debug平臺改為×64位
錯誤解決2:
解決方法:matlab程序返回一個數(shù),而C#代碼接收的是MWArray數(shù)據(jù)。
p3.untitled4((MWArray)25);
運行結(jié)果:
到此這篇關(guān)于C#調(diào)用matlab生成的dll庫的文章就介紹到這了,更多相關(guān)C#調(diào)用matlab生成的dll庫內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
WPF中MVVM工具包CommunityToolkit.Mvvm的使用方式
這篇文章主要介紹了WPF中MVVM工具包CommunityToolkit.Mvvm的使用方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-05-05c#中WebService的介紹及調(diào)用方式小結(jié)
這篇文章主要給大家介紹了關(guān)于c#中的WebService及其調(diào)用方式的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2018-11-11