首页 > 解决方案 > MATLAB Feval C# 客户端缓存问题

问题描述

我需要在 C# 应用程序中运行 MATLAB 代码。我已阅读官方文档以在我的应用程序中运行 MATLAB 函数。

它有效,但我有一个缓存问题。如果我在 C# 中运行给定的 MATLAB 代码:

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, 5, 7, "world"); 

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

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

使用以下 matlab 函数:

function [x,y] = myfunc(a,b,c) 
x = a + b; 
y = sprintf('Hello %s',c); 

如果我在 MATLAB 脚本函数中进行更改x = a + b;x = a * b;应用程序将继续返回 a+b=12 而不是 a*b=35。

如何解决这个缓存问题?

标签: c#matlab

解决方案


推荐阅读