关于matlab与c#混合编程的问题(5)

2025-06-28

是“项目名称Native.dll”,这2个dll的差别可以通过\文件夹源码来观察。“distrib”就是源代码的文件夹。如下图所示,src文件夹的文件示意图:

我们2.2中新建的类名是TestDemo,所以生成的的源码名称也是TestDemo,看看这2个cs文件中的代码,同时类的方法也可以在VS中通过对象浏览器来查看dll有哪些方法以及方法的参数类型。直接贴这2个cs文件的代码,顺便解释和对比下: TestDemo.cs文件源码:

1/*

2* MATLAB Compiler: 4.17 (R2012a) 3* Date: Mon Sep 09 16:19:01 2013

4* Arguments: \\ 5* \

\

6* \ 7* \\ 8* \

\\ 9*/

10using System;

11using System.Reflection;

12using System.IO;

13using MathWorks.MATLAB.NET.Arrays; 14using MathWorks.MATLAB.NET.Utility; 15

16#if SHARED

17 [assembly: System.Reflection.AssemblyKeyFile(@\)] 18#endif 19

20namespace PlotTest 21 { 22

23///

24/// The TestDemo class provides a CLS compliant, MWArray interface to the M-functions

25/// contained in the files: 26///

27/// D:\\Work\\DevelopMent_SVN\\Matlab\\MatlabBlog\\PlotTest.m 28/// 29/// deployprint.m

30/// 31/// printdlg.m 32///

33///

34/// @Version 0.0 35///

36publicclass TestDemo : IDisposable 37 {

38#region Constructors 39

40///

41/// The static constructor instantiates and initializes the MATLAB Compiler Runtime 42/// instance. 43///

44static TestDemo() 45 {

46if (MWMCR.MCRAppInitialized) 47 {

48 Assembly assembly= Assembly.GetExecutingAssembly(); 49

50string ctfFilePath= assembly.Location; 51

52int lastDelimiter= ctfFilePath.LastIndexOf(@\); 53

54 ctfFilePath= ctfFilePath.Remove(lastDelimiter, (ctfFilePath.Length - lastDelimiter)); 55

56string ctfFileName = \; 57

58 Stream embeddedCtfStream = null; 59

60 String[] resourceStrings = assembly.GetManifestResourceNames(); 61

62foreach (String name in resourceStrings) 63 {

64if (name.Contains(ctfFileName)) 65 {

66 embeddedCtfStream =

assembly.GetManifestResourceStream(name); 67break;

68 } 69 }

70 mcr= new MWMCR(\,

71 ctfFilePath, embeddedCtfStream, true); 72 } 73else 74 {

75thrownew ApplicationException(\initialized\); 76 } 77 } 78 79

80///

81/// Constructs a new instance of the TestDemo class. 82///

83public TestDemo() 84 { 85 } 86 87

88#endregion Constructors 89

90#region Finalize 91

92///

93/// Class destructor called by the CLR garbage collector.

94///

95 ~TestDemo() 96 {

97 Dispose(false); 98 } 99 100

101///

102/// Frees the native resources associated with this object 103///

104publicvoid Dispose() 105 {

106 Dispose(true); 107

108 GC.SuppressFinalize(this); 109 } 110 111

112///

115protectedvirtualvoid Dispose(bool disposing) 116 {

117if (!disposed) 118 {

119 disposed= true; 120

121if (disposing) 122 {

123// Free managed resources; 124 } 125

126// Free native resources 127 } 128 } 129 130

131#endregion Finalize 132

133#region Methods 134

135///

136/// Provides a void output, 0-input MWArrayinterface to the PlotTest M-function.

137///

138///

139/// M-Documentation:

140/// 编写一个简单的函数,对plot进行简单封装一下 141/// 142///

143publicvoid PlotTest() 144 {

145 mcr.EvaluateFunction(0, \, new MWArray[]{}); 146 } 147 148

149///

150/// Provides a void output, 1-input MWArrayinterface to the PlotTest M-function.

151///

152///

153/// M-Documentation:

154/// 编写一个简单的函数,对plot进行简单封装一下 155///

156/// 157///

158publicvoid PlotTest(MWArray n) 159 {

160 mcr.EvaluateFunction(0, \, n); 161 } 162 163

164///

165/// Provides the standard 0-input MWArray interface to the PlotTest M-function.

166///

167///

168/// M-Documentation:

169/// 编写一个简单的函数,对plot进行简单封装一下 170///

171///

172///An Array of length \173/// arguments. 174///

175public MWArray[] PlotTest(int numArgsOut) 176 {


关于matlab与c#混合编程的问题(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:《天作之合》中西合璧婚礼主持词

相关阅读
本类排行
× 游客快捷下载通道(下载后可以自由复制和排版)

下载本文档需要支付 7

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:xuecool-com QQ:370150219