calling matlab function in c#

  • Thread starter Thread starter zipls
  • Start date Start date
Z

zipls

suppose a simple matlab function
//add.m
function result=add(left,right)
result=left + right;

//end of add.m

use matlab comtool to encapsulate the function in fun.dll
and then use it in c#.net

i create a c# web service project to call
the matlab function add

but the function declaration has changed:
//create a instance;
fun.funClass st=new fun.funClass();

when i want to write st.add(parameters)

the declaration is
void add(int nargout,ref object,object,object)

which in matlab there're only two (left and right)

Could anyone please tell what's the meaning of int nargout and ref object?
And how to call the function add correctly?
 
Hi,
my guess is
nargout is number of output arguments
ref object will hold the result
the two 'val' objects are the input parameters
So I would be looking for C# code something like
object myResult;
int num1 =5;
int num2 =6;
st.add(1,myResult,num1,num2)
ie the following c# is similar in intent
private void button1_Click(object sender, EventArgs e)

{

int x = 5;

int y = 6;

object myResult;

myResult = new object();

Addem(ref myResult,x,y);

int z;

if( int.TryParse(myResult.ToString(),out z))

MessageBox.Show(" Result is " + z.ToString());

}

private void Addem(ref object myResult, int x, int y)

{

myResult = x + y;

}

HTH

bob
 
Back
Top