C# matlab

编译环境:Microsoft Visual Studio 2008
版本 9.0.21022.8 RTM
Microsoft .NET Framework
版本 3.5
安装的版本: Professional
Microsoft Visual Basic 2008   91986-031-5000002-60050
Microsoft Visual Basic 2008
Microsoft Visual C# 2008   91986-031-5000002-60050
Microsoft Visual C# 2008
Microsoft Visual C++ 2008   91986-031-5000002-60050
Microsoft Visual C++ 2008
Microsoft Visual Studio 2008 Tools for Office   91986-031-5000002-60050
Microsoft Visual Studio 2008 Tools for Office
Microsoft Visual Web Developer 2008   91986-031-5000002-60050
Microsoft Visual Web Developer 2008
Crystal Reports    AAJ6G-K0MSA4K-680002Z
Crystal Reports Basic for Visual Studio 2008

Matlab 2008b
首先需要做的工作是matlab编译器的设置,设置方法为:在Command window中输入mbuild -setup显示如下
>> mbuild -setup
Please choose your compiler for building standalone MATLAB applications:

Would you like mbuild to locate installed compilers [y]/n? n    %选择n
Select a compiler:
[1] Lcc-win32 C 2.4.1
[2] Microsoft Visual C++ 6.0
[3] Microsoft Visual C++ .NET 2003
[4] Microsoft Visual C++ 2005
[5] Microsoft Visual C++ 2005 Express Edition
[6] Microsoft Visual C++ 2008

[0] None
Compiler: 6                             %选择6,其他编译器可以选相应的选项,我没有验证过
The default location for Microsoft Visual C++ 2008 compilers is C:\Program Files\Microsoft Visual Studio 9.0,
but that directory does not exist on this machine.

Use C:\Program Files\Microsoft Visual Studio 9.0 anyway [y]/n? n%选择n
Please enter the location of your compiler: [C:\Program Files\Microsoft Visual Studio 9.0] D:\Program Files\Microsoft Visual Studio 9.0 %选择您自己的当前安装路径
Please verify your choices:

Compiler: Microsoft Visual C++ 2008
Location: D:\Program Files\Microsoft Visual Studio 9.0

Are these correct [y]/n? y  %看上述信息,如果正确选择y
****************************************************************************
  Warning: Applications/components generated using Microsoft Visual Studio  
           2008 require that the Microsoft Visual Studio 2008 run-time      
           libraries be available on the computer used for deployment.      
           To redistribute your applications/components, be sure that the   
           deployment machine has these run-time libraries.                 
****************************************************************************

Trying to update options file: C:\Documents and Settings\Administrator\Application Data\MathWorks\MATLAB\R2008b\compopts.bat
From template:              D:\PROGRA~1\MATLAB\R2008b\bin\win32\mbuildopts\msvc90compp.bat

Done . . .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%至次编译器设置完成%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
在matlab的Command window中输入:
>> deploytool
Matlab产生deployment tool配置窗口



单击新建按钮,新建工程------>选择MATLAB Builder NE 选项卡----->选择.NET Component并添加工程名eaqual(测试用名,其实工程名称就是你导入C#后的命名空间名称,Matlab会在当前工作目录中新建文件夹文件夹名既为equal)---->点击ADD File按钮将你需要编译的MATLAB函数添加进当前工程,我这里导入的是 D:\Program Files\MATLAB\R2008b\toolbox\aero\aero\angle2quat.m文件---->点击build.
deployment tool output 窗口输出以下信息:
Build output( 2009-03-28 15:32:55).

[url=matlab:mcc%20-F%20%27E:%5CMATLAB%5Ceaqual.prj%27]mcc -F 'E:\MATLAB\eaqual.prj'[/url]
等待...................................有点久
当输出以下信息时编译成功了

Compiler version: 4.9 (R2008b) Warning: Duplicate directory name: E:\MATLAB. mcc -W 'dotnet:eaqual,Eaqual,0.0,private' -d 'E:\MATLAB\eaqual\src' -T 'link:lib' -v 'class{Eaqual:\Program Files\MATLAB\R2008b\toolbox\aero\aero\angle2quat.m}' Warning: Name is nonexistent or not a directory: D:\Program Files\MATLAB\R2008b\toolbox\compiler\patch. Warning: Name is nonexistent or not a directory: D:\Program Files\MATLAB\R2008b\toolbox\compiler\patch. Processing D:\Program Files\MATLAB\R2008b\toolbox\aero\mcc.enc Processing D:\Program Files\MATLAB\R2008b\toolbox\matlab\mcc.enc Processing include files... 2 item(s) added. Processing directories installed with MCR... The file E:\MATLAB\eaqual\src\mccExcludedFiles.log contains a list of functions excluded from the CTF archive. 2 item(s) added. Generating MATLAB path for the compiled application... Created 40 path items. Begin validation of MEX files: Sat Mar 28 15:35:11 2009 End validation of MEX files: Sat Mar 28 15:35:11 2009 Warning: Name is nonexistent or not a directory: D:\Program Files\MATLAB\R2008b\toolbox\compiler\patch. Deleting 0 temporary MEX authorization files. Parsing file "D:\Program Files\MATLAB\R2008b\toolbox\aero\aero\angle2quat.m" (Referenced from: "Compiler Command Line"). Parsing file "D:\Program Files\MATLAB\R2008b\toolbox\compiler\deploy\deployprint.m" (Referenced from: "Compiler Command Line"). Parsing file "D:\Program Files\MATLAB\R2008b\toolbox\compiler\deploy\printdlg.m" (Referenced from: "Compiler Command Line"). Generating file "E:\MATLAB\eaqual\src\Eaqual.cs". Generating file "E:\MATLAB\eaqual\src\EaqualNative.cs". Generating file "E:\MATLAB\eaqual\src\readme.txt". Generating file "E:\MATLAB\eaqual\src\dotnet_mcc_component_data.cs". Executing command: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe /nologo /optimize /doc:"E:\MATLAB\eaqual\src\eaqual.xml" /t:library /r:"D:\Program Files\MATLAB\R2008b\toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll" /resource:"E:\MATLAB\eaqual\src\eaqual.ctf" /out:"E:\MATLAB\eaqual\src\eaqual.dll" "E:\MATLAB\eaqual\src\Eaqual.cs" "E:\MATLAB\eaqual\src\dotnet_mcc_component_data.cs" Executing command: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe /nologo /optimize /doc:"E:\MATLAB\eaqual\src\eaqualNative.xml" /t:library /r:"D:\Program Files\MATLAB\R2008b\toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll" /resource:"E:\MATLAB\eaqual\src\eaqual.ctf" /out:"E:\MATLAB\eaqual\src\eaqualNative.dll" "E:\MATLAB\eaqual\src\EaqualNative.cs" "E:\MATLAB\eaqual\src\dotnet_mcc_component_data.cs"   
Copying: E:\MATLAB\eaqual\src\eaqual.dll -> E:\MATLAB\eaqual\distrib
Copying: E:\MATLAB\eaqual\src\eaqualNative.dll -> E:\MATLAB\eaqual\distrib
Copying: E:\MATLAB\eaqual\src\readme.txt -> E:\MATLAB\eaqual\distrib
Compilation completed succesfully. The output is located in E:\MATLAB\eaqual\distrib.
You can package the component by clicking on the "ackage" icon in the Deployment Tool toolbar, or by clicking the Tools->ackage menu when the Deployment Tool panel is selected. To include additional files in the package, click Project->Settings).


生成的文件在工程文件夹里面
我的是  E:\MATLAB\eaqual\distrib\angle2quat.dll
至此MATLAB的操作全部完成

打开VISUAL Studio 2008新建C#工程我这里用的是控制台名为TestOfmatlab_consolt
我的是  E:\Visual Studio 2008\Projects\TEST\TestOfmatlab_consolt
添加引用E:\MATLAB\eaqual\distrib\angle2quat.dll
和D:\Program Files\MATLAB\R2008b\toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll
(这里我没有用MATLAB画图,所以只引用MWArray.dll)
加入命名空间:
using MathWorks.MATLAB.NET.Arrays;
将下面代码加入Main函数
            eaqual.Eaqual eq=new eaqual.Eaqual();
            MathWorks.MATLAB.NET.Arrays.MWArray m=10,n=4,j=7,k;

           
             MWArray S = "XYZ";

            k = eq.angle2quat((MWNumericArray)m, (MWNumericArray)n, (MWNumericArray)j,

                               (MWCharArray)S);
            MWNumericArray temp = (MWNumericArray)k;
            double[,] location = (double[,])temp.ToArray(MWArrayComponent.Real);
            Console.WriteLine(location[0,0].ToString());
            Console.WriteLine(location[0,1].ToString());
            Console.WriteLine(k[2].ToString());
            Console.WriteLine(k[3].ToString());
            Console.WriteLine(k[4].ToString());
            Console.ReadLine();


编译运行即可看到输出,此函数是姿态角转四元数函数,具体功能就不做说明了。这个例子输入输出参数转换关系都有,大家自己看看就明白了


文件源代码:C#工程源码
由于工程文件过大就只把主函数源码传上来了!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/388690.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

洛谷P3273 [SCOI2011] 棘手的操作 [左偏树]

题目传送门 棘手的操作 题目描述 有N个节点,标号从1到N,这N个节点一开始相互不连通。第i个节点的初始权值为a[i],接下来有如下一些操作: U x y: 加一条边,连接第x个节点和第y个节点A1 x v: 将第x个节点的权值增加vA2 x…

基于容器制作镜像

一。镜像基础 一。基于容器制作镜像 1. 查看并关联运行的容器 [ghlocalhost ~]$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 4da438fc9a8e busybox …

照顾好自己才能照顾好别人_您必须照顾的5个基本数据

照顾好自己才能照顾好别人I am pretty sure that on your data journey you came across some courses, videos, articles, maybe use cases where someone takes some data, builds a classification/regression model, shows you great results, you learn how that model wo…

matlab数字仿真实验,DVR+备用电源自动投入的MATLAB数字仿真实验仿真实验

一、动态电压恢复器(DVR)的数字仿真实验动态电压恢复器(Dynamic Voltage Restorer,DVR)是一种基于电力电子技术的串联补偿装置,通常安装在电源与敏感负荷之间,其作用在于:保证电网供电质量,补偿供电电网产生的电压跌落…

c#,xp系统,Matlab6.5

编译环境:c#,xp系统,Matlab6.5 新建一个窗体项目,添加matlab引用。 然后试了四种方式调用matlab: 第一种 view plaincopy to clipboardprint?MLApp.MLAppClass matlab new MLApp.MLAppClass(); matlab.Visible 1;…

java script 对象

java script 对象 1.创建方式 1)通过字面量的形式创建 例;var stt{x:1,y:2,y:3}; 或;var stt{ x:1, y:2, for:3 } 注意关键字必须放到引号中间 2)通过new创建对象 例:var new stt(); stt.name 小鱼; stt.age 20…

认识数据分析_认识您的最佳探索数据分析新朋友

认识数据分析Visualization often plays a minimal role in the data science and model-building process, yet Tukey, the creator of Exploratory Data Analysis, specifically advocated for the heavy use of visualization to address the limitations of numerical indi…

架构探险笔记10-框架优化之文件上传

确定文件上传使用场景 通常情况下,我们可以通过一个form(表单)来上传文件,就以下面的“创建客户”为例来说明(对应的文件名是customer_create.jsp),需要提供一个form,并将其enctype属…

matlab飞行数据仿真,基于MATLAB的飞行仿真

收稿日期: 2005 - 05 - 15   第 23卷  第 06期 计  算  机  仿  真 2006年 06月    文章编号: 1006 - 9348 (2006) 06 - 0057 - 05 基于 MATLAB的飞行仿真 张镭 ,姜洪洲 ,齐潘国 ,李洪人 (哈尔滨工业大学电液伺服仿真及试验系统研究所 ,黑龙江 哈尔滨 150001) 摘要:该…

Windows Server 2003 DNS服务安装篇

导读-- DNS(Domain Name System,域名系统)是一种组织成层次结构的分布式数据库,里面包含有从DNS域名到各种数据类型(如IP地址)的映射“贵有恒,何必三更起五更勤;最无益,只怕一日曝十日寒。”前一段时间巴哥因为一些生活琐事而中止…

正则表达式matlab,正则表达式中一个word的匹配 @MATLAB - 优秀的Free OS(Linux)版 - 北大未名BBS...

我目前想做的就是判断一个str是否可以被认为是有效的MATLAB index。最好的方法是直接运行,然后看运行结果或报错类型,但是我不打算在不知道是什么类型的东西之前运行它,所以可以预先parse一下,简单判断是否“长得跟有效的MATLAB i…

arima模型怎么拟合_7个统计测试,用于验证和帮助拟合ARIMA模型

arima模型怎么拟合什么是ARIMA? (What is ARIMA?) ARIMA models are one of the most classic and most widely used statistical forecasting techniques when dealing with univariate time series. It basically uses the lag values and lagged forecast error…

jQuery禁止Ajax请求缓存

一 现象 get请求在有些浏览器中会缓存。浏览器不会发送请求,而是使用上次请求获取到的结果。 post请求不会缓存。每次都会发送请求。 二 解决 jQuery提供了禁止Ajax请求缓存的方法: $.ajax({type: "get",url: "http://www.baidu.com?_&…

python 实例

参考 http://developer.51cto.com/art/201804/570408.htm 转载于:https://www.cnblogs.com/artesian0526/p/9552510.html

[WPF]ListView点击列头排序功能实现

[WPF]ListView点击列头排序功能实现 这是一个非常常见的功能,要求也很简单,在Column Header上显示一个小三角表示表示现在是在哪个Header上的正序还是倒序就可以了。微软的MSDN也已经提供了实现方式。微软的方法中,是通过ColumnHeader Templ…

天池幸福感的数据处理_了解幸福感与数据(第1部分)

天池幸福感的数据处理In these exceptional times, the lockdown left many of us with a lot of time to think. Think about the past and the future. Think about our way of life and our achievements. But most importantly, think about what has been and would be ou…

标线markLine的用法

series: [{markLine: {itemStyle: {normal: { lineStyle: { type: solid, color:#000 },label: { show: true, position:left } }},data: [{name: 平均线,// 支持 average, min, maxtype: average},{name: Y 轴值为 100 的水平线,yAxis: 100},[{// 起点和终点的项会共用一个 na…

php pfm 改端口,罗马2ESF和PFM 修改建筑 军团 派系 兵种等等等很多东西的教程

本帖最后由 clueber 于 2013-10-5 12:30 编辑本人是个罗马死忠加修改党,恩,所以分享一下自己的修改心得修改工具为ESF1.0.7和PFM3.0.3首先是ESF修改。ESF可以用来改开局设定和存档,修改开局设定是startpos.esf文件,在存档在我这里…

红草绿叶

从小到大喜欢阴天,喜欢下雨,喜欢那种潮湿的感觉。却又丝毫容不得脚上有一丝的水汽,也极其讨厌穿凉鞋。小时候特别喜欢去山上玩,偷桃子柿子,一切一切都成了美好的回忆,长大了,那些事情就都不复存…

wpf listview 使用

单列&#xff1a; <ListView Grid.Column"1" Height"284" HorizontalAlignment"Left" Margin"64,73,0,0" Name"listView1" VerticalAlignment"Top" Width"310" > <ListView.Items…