calling matlab function in c#

E

eric_jin

i wrote a c# webservice to call matlab functions.

add is the function written in matlab,and then make it dll to use in c#;

//add.m
function result=add(left,right)
result=left + right;

//end of add.m

//calling add in c#


[webmethod]
public double add(double left,double right)
{
fun.funClass st=new fun.funClass();
object b=new object();
st.add(1,ref b,left,right); //$breakpoint here;
double c=(double)b;
return c;

}

but this returns an error in c# where left is set to 4 and right is 5;
when i set a breakpoint in line$;it showed that b is of value 9,which means
the function was correctly
called from matlab;
but when i tried to transform object b to double-tpye,
//double c=(double)b;
it returns an error;
could anybody please tell me why it can not work?
 
B

bob

Hi,
See what happens with
double c;
if(double.tryparse(b.Tostring(),out c))
//success
Bob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top