詳解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)建一個(gè)。
錯(cuò)誤解決:
解決方法:將matlab程序改寫成一個(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é)果:
到此這篇關(guān)于C#調(diào)用matlab生成的dll庫的文章就介紹到這了,更多相關(guān)C#調(diào)用matlab生成的dll庫內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
WPF中MVVM工具包CommunityToolkit.Mvvm的使用方式
這篇文章主要介紹了WPF中MVVM工具包CommunityToolkit.Mvvm的使用方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-05-05c#中WebService的介紹及調(diào)用方式小結(jié)
這篇文章主要給大家介紹了關(guān)于c#中的WebService及其調(diào)用方式的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2018-11-11C#正則函數(shù)用法實(shí)例【匹配、替換、提取】
這篇文章主要介紹了C#正則函數(shù)用法,結(jié)合實(shí)例形式分析了C#基于正則的匹配、替換、提取相關(guān)操作技巧,需要的朋友可以參考下2017-01-01