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

2025-06-28

177return mcr.EvaluateFunction(numArgsOut, \, new MWArray[]{}); 178 } 179 180

181///

182/// Provides the standard 1-input MWArray interface to the PlotTest M-function.

183///

184///

185/// M-Documentation:

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

188///

189///

190///An Array of length \191/// arguments. 192///

193public MWArray[] PlotTest(int numArgsOut, MWArray n) 194 {

195return mcr.EvaluateFunction(numArgsOut, \, n); 196 } 197 198 199

200///

201/// This method will cause a MATLAB figure window to behave as a modal dialog box.

202/// The method will not return until all the figure windows associated with this

203/// component have been closed. 204///

205///

206/// An application should only call this method when required to keep the

207/// MATLAB figure window from disappearing. Other techniques, such as calling 208/// Console.ReadLine() from the application should be considered where 209/// possible. 210///

211publicvoid WaitForFiguresToDie() 212 {

213 mcr.WaitForFiguresToDie();

214 } 215 216 217

218#endregion Methods 219

220#region Class Members 221

222privatestatic MWMCR mcr= null; 223

224privatebool disposed= false; 225

226#endregion Class Members 227 } 228 }

TestDemoNative.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 PlotTestNative 21 { 22

23///

24/// The TestDemo class provides a CLS compliant, Object (native) interface to the

25/// M-functions 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 Objectinterface to the PlotTest M-function.

137///

138///

139/// M-Documentation:

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

143publicvoid PlotTest()


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

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

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

下载本文档需要支付 7

支付方式:

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

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