【问题标题】:Reading value from matlab function in c#从 C# 中的 matlab 函数中读取值
【发布时间】:2013-12-06 13:17:35
【问题描述】:

我有 matlab 包装的 .dll 文件,想在其中显示一个函数的值。

我的代码看起来像

plotting plot= new plotting();
double a=1;
doubleb=2.2;
object x=plotting.plotMe(a,b);
Console.WriteLine(x.ToString());

它显示 z=3.2,它由 matlab 函数返回为 a+b,而我的 Console.WriteLine(x.ToString()) 返回 System.Double[,]。我想保持 z 的值并稍后在我的代码中以某种方式使用它。

matlab函数定义如下:

object[] plotting.plotMe(int numArgsOut,object a,object b) 

如果你能帮助我,我将不胜感激。

【问题讨论】:

    标签: c# matlab word-wrap


    【解决方案1】:

    如果 plotting.plotMe() 将可靠地返回相同的格式,一个简单的解决方案是获取等号后面的字符串部分并解析它。可以通过查找等号的索引或拆分字符串来完成,或者但是。类似的东西

    String numString = x.ToString().Split('=')[1]; // (1) because we want the piece to the right
    double num = Double.Parse(numString);
    

    应该可以。

    【讨论】:

    • 感谢您的回复。它给出了一个例外,并在 String numString = x.ToString().Split('=')[1]; 处显示“索引超出了数组的范围”;
    • 如果是这种情况,那么(在这次运行中),x.ToString() 中没有等号。再试一次,但在拆分之前让它打印 x.ToString()。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 2014-10-27
    • 1970-01-01
    • 1970-01-01
    • 2014-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多