如何在c#中使用feval matlab [英] How to use feval matlab in c#

查看:120
本文介绍了如何在c#中使用feval matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在matlab中创建了一个名为segment的函数,我想从c#程序调用它。

它需要2个参数string and integer

它返回6数组

这是我的代码:

i create a function in matlab called segment, and i want to call it from c# program
it takes 2 argument "string and integer"
and it returns 6 arrays
this is my code :

var activationContext = Type.GetTypeFromProgID("matlab.application.single");
var matlab = (MLApp.MLApp)Activator.CreateInstance(activationContext);
matlab.Visible = 0;
string name = Openfile.FileName;
int num = 0;
var result = matlab.Feval("WBC_SegProposed", 6, name,num);





但它在最后一条指令上给我错误,就是错误

错误1'MLApp.DIMLApp.Feval的最佳重载方法匹配(字符串,整数,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象,对象)'有一些无效的参数




即使这条指令也给我错误

a = matlab.Feval(strcat,1,hello,world)

我该怎么办?



but it give me error at the last instruction, that is the error
Error 1 The best overloaded method match for 'MLApp.DIMLApp.Feval(string, int, out object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object)' has some invalid arguments


even this instruction give me error
a = matlab.Feval("strcat", 1, "hello", "world")
what shall i do ?

推荐答案

这个看起来像是 COM接口周围的c#包装器不是将结果作为正常返回值返回,而不是通过 out 参数返回它。所以你的代码看起来像:

This looks like the c# wrapper around the COM interface is not returning the result as a normal return value, rather it is returning it via an out parameter. So your code would look like:
object result;
matlab.Feval("WBC_SegProposed", 6, out result, name, num);



如果附加参数不是默认,那么你需要一个适当数量的 null 值来完成参数列表。



免责声明:我过去使用过Matlab,但我目前没有副本,所以我不能尝试这个。这是我的最佳猜测


If the additional arguments were not "defaulted" then you'll need an appropriate number of null values to complete the argument list.

Disclaimer: I've used Matlab in the past but I do not have a copy currently so I cannot try this. This is my best guess.


这篇关于如何在c#中使用feval matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆