Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 :
C#
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);


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 ?
Posted
Updated 25-Nov-19 0:02am

1 solution

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:
C#
object result;
matlab.Feval("WBC_SegProposed", 6, out result, name, num);

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.
 
Share this answer
 
Comments
Esraa Saady 8-Jul-14 15:12pm    
thank you very much...the error is gone :)
Esraa Saady 8-Jul-14 15:25pm    
do you have any idea how i can receive a lot of output parameters from the function in c# ??
Matt T Heffron 8-Jul-14 15:56pm    
Like I stated, I don't have Matlab installed and I've never used the COM interface either. So I'm not sure.
Is the result object returned a single value, or is it an array (COM SAFEARRAY) of all of the returned values?
Just a thought.
Esraa Saady 8-Jul-14 16:20pm    
thanks for answering me :) .. it works know

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900