has anyone successfully called matlab functions in c#?

E

eric_jin

i called function show() in a c# webservice

//show.m
function ans=show(x)
ans=x;
it works;
but when i try to call add(),it breaks;


//add.m
function ans=add(a,b)
ans=a+b;


code in c# as follows:
[WebMethod]
public int show()
{
mat.matClass st=new mat.matClass();
object obj=new object();
st.show(1,ref obj,4);
return (int)obj;



}


this returns 4;

but the following:


[WebMethod]
public int add()
{
mat.matClass st=new mat.matClass();
object obj=new object();
st.add(1,ref obj,4,5);
return (int)obj;



}


this breaks down.
could anyone please help me with it?
thanks!



P.S

while debugging i learn that this program breaks at line:
st.add(1,ref obj,4,5);
which means the function wrttin in matlab wasn't correctly called;
 
G

Guest

The exception type and message would be helpful. Also, I'm assumming you
used the MATLAB Compiler to create a dll from your .m files. Provide more
information on how you have everything set up.

You might want to also consider MATLAB Builder for .NET. Go the the
Mathworks website and check it out. It's an extension of the MATLAB Compiler
that creates .NET assemblies out of MATLAB code.
 
B

bob

Hi eric,
As a test have you tried?
object obj = new object();
object a = new object();
object b=new object();
a=4;
b=5;
st.add(1,ref obj,4,5);
....

I see that st.show accepts the integer 'directly',
but its worth a test
regards
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