主要内容

测试您的 .NET 开发环境

MATLAB® Engine API for .NET 附带示例 C# 代码,您可以使用这些代码来测试您的环境并熟悉引擎 API 的使用。源代码位于 fullfile(matlabroot,"extern","examples","engines","dotnet") 定义的文件夹中,其中 matlabroot 是 MATLAB matlabroot 命令返回的路径。

该文件夹包含:

  • dotnet_engine_examples.sln - Microsoft® Visual Studio® 工程文件。

  • .cs 文件 - C# 源文件。这些应用程序:

    • 启动 MATLAB 实例并连接到它。

    • 关闭和处置 MATLAB 会话。

    Program.cs 文件是控制台应用程序,运行工程中包含的所有示例文件。

    MainWindow.xaml.cs 文件是 Windows® GUI 应用程序,根据用户输入计算阶乘。

  • README - 描述如何使用 Visual Studio 编译和运行示例的文本文件。

使用 MATLAB copyfile 函数将文件复制到路径中的一个可写文件夹:

copyfile(fullfile(matlabroot,"extern","examples","engines","dotnet","dotnet_engine_examples.sln"),".","f")
copyfile(fullfile(matlabroot,"extern","examples","engines","dotnet","console\*.*"),".\console\","f")

如果您在 Windows 平台上:

copyfile(fullfile(matlabroot,"extern","examples","engines","dotnet","gui\*.*"),".\gui\","f")

按照 README 文件中的这些说明编译并运行示例:

  • 验证您安装了受支持的 .NET 版本

  • 设置运行时环境变量

  • matlabroot/extern/examples/engines/dotnet 文件夹调用 dotnet build

  • matlabroot/extern/examples/engines/dotnet/console 文件夹调用 dotnet run

  • 在 Windows 平台上,从 matlabroot/extern/examples/engines/dotnet/gui 文件夹调用 dotnet run

另请参阅

主题