首页 > 解决方案 > 自动化 matlab 代码,但在我的 Matlab 路径上找不到函数

问题描述

我在使用 Matlab 时遇到问题。

我有 ac# 包装器,它创建了一个 Matlab 实例并将目录更改为我拥有各种功能的位置。然后我调用所需的 Matlab 函数。

当该函数调用不在同一目录中但在我的 Matlab 路径上的另一个函数时,就会出现问题。Matlab 说找不到函数。只是为了使情况更加混乱,一些位于不同目录中的函数确实有效。

在我的 Matlab 中,我有一个 startup.m 文件,它加载了我所有需要的路径。这是通过 C# 创建 Matlab 实例时执行的吗?

如果我从 Matlab 手动运行代码,则代码可以完美运行。

 MLApp.MLApp _matlab;


  try
        {
            // create matlab instance
            _matlab = new MLApp.MLApp();

            // change to the directory where the function is located            
            _matlab.Execute(@"cd G:\MyPath\production\SomeFolder\");

            // define the output
            object result = null;

            // call the matlab function upload_data            
            _matlab.Feval("someFunctionName", 0, out result, "parameter");

            // quit matlab
            _matlab.Quit();

            // display result
            object[] res = result as object[];
        }
        catch(Exception ex)
        {
            _matlab.Quit();
            throw;
        }

标签: c#.netmatlab

解决方案


推荐阅读