c 与matlab混编,谈谈Matlab与C/C++或C#的互调用(混合编程)
记得当初一个师姐问我知不知道如何在Matlab里调用C++的程序,还真把我问住了。因为我以前就知道C++调用Matlab的方法,这方面网上资料一大堆。没想到现在自己突发奇想又遇到另外一个问题,Matlab如何调用C#开发的程序。
1、C/C++调用Matlab
这方面资料太多了,随便搜一下“Matlab C++ 混合编程”。
2、Matlab调用C/C++
3、C#调用Matlab
这个我的博客Matlab分类有。
4、Matlab调用C#
通常是两种方法:COM和非托管化
但是,事实上matlab call dll,这个dll本身就可以是.net开发的,Matlab提供了相关加载和转换的函数。这才是本文的亮点。
下面是matlab的相关命令介绍
http://www.mathworks.com/access/helpdesk/help/techdoc/ref/f16-35614.html#brxerx8-1
Matlab使用.net数据的例子
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/exampleindex.html
下面是展示一些简单的例子和过程。
SampleProperties Class.
using System;
namespace netdoc
{
class SampleProperties
{
// string property
private static string stringField = "The MathWorks";
public static string stringProp
{
get { return stringField; }
set { stringField = value; }
}
// read/write property
private double doubleField = 8.9;
public double doubleProp
{
get { return doubleField; }
set { doubleField = value; }
}
// read-only property
private double readField = 0;
public double readOnlyProp
{
get { return readField; }
}
// write-only property
private double writeField = 0;
public double writeOnlyProp
{
set { writeField = value; }
}
}
}
Create Object.
Load the assembly and create object obj
:
sampleInfo = NET.addAssembly('c:/work/NetSample.dll');
obj = netdoc.SampleProperties
MATLAB displays the object as follows:
obj =
netdoc.SampleProperties handle
Package: netdoc
Properties:
stringProp: [1x1 System.String]
doubleProp: 8.9000
readOnlyProp: 0
Methods, Events, Superclasses
MATLAB displays the stringProp
, doubleProp
, and readOnlyProp
properties, but not the writeOnlyProp
property. MATLAB also does not display properties defined with the private
keyword, such as stringField
and doubleField
.
View Property Values.
To view the value of stringProp
, type:
obj.stringProp
MATLAB displays:
ans =
The MathWorks
Use Property
Values.
To use the properties, type:
db1 = obj.doubleProp
db2 = obj.readOnlyProp
MATLAB displays:
db1 =
8.9000
db2 =
0
Modify Property
Values.
To modify the properties, type:
obj.doubleProp = 5;
obj.writeOnlyProp = 6;
obj
MATLAB displays (in part):
obj =
Properties:
stringProp: [1x1 System.String]
doubleProp: 5
readOnlyProp: 0
To modify the static property stringProp
, type:
NET.setStaticProperty('netdoc.SampleProperties.stringProp', ...
'This is a static property');
newVal = obj.stringProp
MATLAB displays:
newVal =
This is a static property
Using .NET Fields
Example
The SampleFields
class defines the following
fields:
·
publicField
·
protectedField
SampleFields Class.
using System;
namespace netdoc
{
class SampleFields
{
public Int32 publicField;
protected string protectedField;
}
}
Create Object.
Load the assembly and create object obj
:
NET.addAssembly('c:/work/NetSample.dll')
obj = netdoc.SampleFields;
Modify Field Values.
To set the value of the field publicField
, type:
myValue = 3;
obj.publicField = myValue
MATLAB displays:
obj =
netdoc.SampleFields handle
Package: netdoc
Properties:
publicField: 3
Methods, Events, Superclasses
The publicField
property is of type Int32
. When you set the value to myValue
, which is of MATLAB type double
, MATLAB automatically converts the value to the proper type, as described in Passing
Data to a .NET Object
. Type:
class(myValue)
class(obj.publicField)
MATLAB displays:
ans =
double
ans =
int32
Limitations
to Support of .NET Properties
You cannot pass a cell array to a
property, or view protected
properties in MATLAB.
Example — Passing Data To a .NET
Assembly将Matlab矩阵转变为.net数组
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/brxe1ww-1.html#brzmvt8-1
Example — Converting a Multidimensional
.NET Array 将.net数组转变为Matlab矩阵
http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/brxe1ww-1.html#br1adia-1
c 与matlab混编,谈谈Matlab与C/C++或C#的互调用(混合编程)相关推荐
- matlab振动频谱分析是不是要,VB和Matlab混编实现振动信号的频谱分析
VB和Matlab混编实现振动信号的频谱分析 3 0 物理测试 2 O O 4年第 2期 V B和 Ma t l a b混编实现振动信号的频谱分析 谭轶平, 王振清 ( 北京航空航天大学材料学院,北京 ...
- mac下配置进行c和matlab混编
mac下配置进行c和matlab混编 是用mac的小伙伴有时候有没有感觉很痛苦!遇到什么问题,找相关的解决办法真心不方便,我最近在搞一段程序,要进行c和matlab的混编,可是,在matlab中输入: ...
- 解决了java+matlab混编+web(jsp)调用Matlab,网页中显示Figure,详细实例
例子简介 网上java+matlab混编的挺多,大多数实例也都能实现出来,但是将matlab生成出来Figure显示在jsp页面中并配合WebFigure实现的例子却很少,所以我将自己的尝试结果详细的 ...
- wpf matlab混编,WPF(C#)与MATLAB混合编程
WPF(C#)与MATLAB混合编程 WPF可以为开发者提供便捷地构建用户交互界面的解决方法,而matlab则在科学计算方面有着无与伦比的优势,因此在一些需要将科学算法转换为应用软件的项目中,需要应用 ...
- 【javamatlab】以一个简单的例子实现java和matlab混编
目录 使用环境: MATLAB: matlab代码: 将matlab代码打包: eclipse: jar包配置: 使用jar包: 使用环境: jdk8(ide使用eclipse2019-6).matl ...
- m 文件 dll matlab 中调用_Java与MatLab混编
该篇介绍Java与MatLab的混合编程 环境:Windows10,Jdk 1.8.0_261 64位,MatLab r2018b 64位 先安装MatLab MatLab安装 一.打开MatLab, ...
- c 与matlab混编,C与MATLAB混合编程之调用MATLAB引擎
Visual Studio调用MATLAB需要的配置已经在<Visual Studio调用MATLAB的配置>一文中给出了详细的步骤,本文将介绍混合编程的示例. 在C中调用MATLAB,据 ...
- python与matlab混合编程_python 与 matlab 混编
Matlab的官方文档中介绍了 Matlab 与其余编程语言之间的引擎接口,其中包括对于 Python 开放的引擎 API,可参考官方教程,其中包括引擎安装,基本使用,以及Python与Matlab之 ...
- QT matlab 混编-qt调用matlab生成dll
前言 环境: win10 Qt5.12 mingW(64位) matlab2019a(64位)----mingw w64 主要参考的文章:1. https://blog.csdn.net/Justic ...
最新文章
- YOLOV4各个创新功能模块技术分析(一)
- bash给脚本加进度条_进度条——shell脚本实现
- TensorSpace:超酷炫3D神经网络可视化框架
- 滴滴基于 Flink 的实时数仓建设实践
- NSPredicate的用法、数组去重、比较...
- Spring @Lazy批注用例
- 性能压测工具选型对比
- mysql 表2符合表1_MYSQL-表1和表2中所有可能性的所有行
- java 查看虚拟机状态_深入理解java虚拟机学习笔记(四)虚拟机性能监控与故障处理工具...
- 2D Perlin噪点
- php访问父类的所有属性,php – 在父类中使用$this仅在子类中显示父类属性
- python猫狗大战pytorch_深度学习实战---猫狗大战(pytorch实现)
- Visio搜索形状显示无匹配项的解决方法
- [转]计算机四级网络工程师思维导图--常考重点
- 科学的软件测试培训时间是多久?
- 金蝶加密服务器出现系统错误,金蝶KIS访问加密服务器失败,可能加密服务器未启动,错误代码5...
- 一杯清茶nbsp;几许相思
- numpy简单实现梯度投影法
- 北大最强扫地僧“韦东奕”爆红全网
- 客户端与服务器端的区别