我有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函数返回为+ b,我的Console.WriteLine(x.ToString())
返回System.Double[,]
。我想保留z的值,稍后在我的代码中使用它。
matlab函数定义如下:
object[] plotting.plotMe(int numArgsOut,object a,object b)
如果你帮助我,我将不胜感激。
答案 0 :(得分:0)
如果plotting.plotMe()要可靠地返回相同的格式,一个简单的解决方案是在等号后取字符串的一部分并解析它。可以通过查找等号的索引或拆分字符串来完成。像
这样的东西String numString = x.ToString().Split('=')[1]; // (1) because we want the piece to the right
double num = Double.Parse(numString);
应该有用。