Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 调用matlab函数,结果总是一样的_C#_Matlab - Fatal编程技术网

C# 调用matlab函数,结果总是一样的

C# 调用matlab函数,结果总是一样的,c#,matlab,C#,Matlab,我创建了一个C#程序,它调用一个matlab函数,然后发生了一些奇怪的事情。 代码非常简单,我只在下面列出它们: Programm.cs: static void Main(string[] args) { // Create the MATLAB instance MLApp.MLApp matlab = new MLApp.MLApp(); // Change to the directory where the funct

我创建了一个C#程序,它调用一个matlab函数,然后发生了一些奇怪的事情。 代码非常简单,我只在下面列出它们:

Programm.cs:

    static void Main(string[] args)
    {
        // Create the MATLAB instance 
        MLApp.MLApp matlab = new MLApp.MLApp();

        // Change to the directory where the function is located
        string path = Directory.GetCurrentDirectory();
        matlab.Execute("cd " + path);

        // Define the output 
        object result = null;

        // Call the MATLAB function myfunc
        matlab.Feval("myfunc", 2, out result, 3.14, 42, "world");

        // Display result 
        object[] res = result as object[];

        Console.WriteLine(res[0]);
        Console.WriteLine(res[1]);
        Console.ReadLine();
    }
myfunc.m:

   function [x,y] = myfunc(a,b,c) 
   x = a + b; 
   y = sprintf('Hello %s', c); 
每次运行代码时,输出总是相同的,即使我更改了matlab函数体或参数值

有没有人遇到过同样的问题

我使用VisualStudio2019和matlab2016

附言。
如果你发现我的书面英语有任何错误,请告诉我。提前谢谢

非常感谢。@platypurty如下:matlab.Feval(“myfunc”,1,out result,new object[]{3.14,42,“world”}),然后让myfunc(x)谢谢你,jdweng。遵循您的建议,代码就会很好地工作。但是上面提到的问题仍然存在。@jdwengar既然它是一个数组,你在matlab x[1]x[2]和x[3]中使用它吗?所以当你在c#中完成时,设置matlab=null。Matlab许可仅允许许可证的一个实例。Matlab将等到一个实例完成后再运行第二个实例。因此,Feval必须异步运行或获取异常。