我如何用c#编译MATLAB exe
本文关键字:MATLAB exe 编译 何用 | 更新日期: 2023-09-27 18:07:09
我如何使用/启动MATLAB文件,编译成exe文件,与c# ?我在MATLAB中创建了一个3D绘图,我想在c#中执行。这可能吗?
我找到的c#代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
// Create the MATLAB instance
MLApp.MLApp matlab = new MLApp.MLApp();
// Change to the directory where the function is located
matlab.Execute(@"cd c:'temp'example");
// Define the output
object result = null;
// Call the MATLAB function myfunc
matlab.Feval("myfunc", 2, out result, 3.14, 42.0, "world");
// Display result
object[] res = result as object[];
Console.WriteLine(res[0]);
Console.WriteLine(res[1]);
Console.ReadLine();
}
}
}
您的示例所在的Mathworks网站还解释了您必须做些什么才能使其工作。1. 创建一个MATLAB函数myfunc,在文件夹c:'temp'example.
function [x,y] = myfunc(a,b,c)
x = a + b;
y = sprintf('Hello %s',c);
- 创建c#应用程序
- 在Microsoft®Visual Studio®中,向MATLAB COM对象添加对c#项目的引用。在Project菜单中,选择Add Reference。
- 在"添加引用"对话框中选择"COM"页签。
- 选择MATLAB应用程序