首页 > 解决方案 > 从 Matlab 到 C# 的输出参数太多

问题描述

我正在从 C# 应用程序运行 Matlab 函数。我希望我的 Matlab 函数向我的 c# 应用程序返回一个值。

但是我收到下面的错误消息。我很困惑,因为我只期待一个值,所以不知道为什么这个错误消息告诉我?

使用 someFunction 时出错 输出参数过多。

MATLAB

  function [success] = autoRun_someFunction

  try
     someFunction;
     success = 1;
  catch ME
     success = getReport(ME, 'extended');
  end

C#

FunctionName = "autoRun_someFunction";

 public string RunMatlabScriptResult(string FunctionDirectory, string FunctionName)
        {
                // create matlab instance
                _matlab = new MLApp.MLApp();

                // change to the directory where the function is located            
                string pathChecker = @"C:\MyFolder\";

                _matlab.Execute(@"cd " + pathChecker);

                // call the matlab is checking the search path    
                object resultChk = null;
                 _matlab.Feval("check_path", 0, out resultChk);

                // change to the directory where the function is located 
                _matlab.Execute(@"cd " + FunctionDirectory);

                // define the output
                object result = null;

                // call the matlab function upload_data                                
                _matlab.Feval(FunctionName, 1, out result);

                // quit matlab
                _matlab.Quit();

                // display result
                object[] res = result as object[];
                return res[0].ToString();                
        }

标签: c#.netmatlab

解决方案


推荐阅读