Click here to Skip to main content
15,883,873 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
hi
I Need some help with the calling of a matlab compiled DLL (C# under
deploytool). The matlab function is a simple function THAT takes two double and return a
third...

i add necessary references to my c# project ...

and its my code :


C#
Sum.Class1 a = new Sum.Class1();
           MathWorks.MATLAB.NET.Arrays.MWArray[,] s=new MWArray[1,3];

           a.sumab(2, 5, s);

             listBox1 .Items.Add(s);



the method (sumab) return void and i dont know how can get my output ...
im very amazing

if i just write a.sumab(2,5);
it gives me an error:

"
CSS
... MWMCR::EvaluateFunction error ...
Error using ==> sumab
Too many output arguments..

"

please help me friends
tnx a lot
Posted
Updated 28-Aug-12 3:32am
v2

1 solution

It seems the function in the DLL is at least called. But of course if the function expects 3 Parameters the call
C#
a.sumab(2,5);
will produce an error. Usually in matlab if you want a return value from a function you call it
C#
s = a.sumab(2, 5); 
since matlab doesnt have reference parameters.

I think you should rewrite your Matlab function so that it only excepts 2 parameters and of course returns the result sum.

See for example:
http://thinkmetric.com/tuts/matlab/functions.html[^]

But then again why even use Matlab for such a simple task...
 
Share this answer
 
Comments
sahrarainmelody 29-Aug-12 1:13am    
i have a great program in matlab and i shoud convert it to dll for using in c# .... this is a simple instance for doing that .
my function in MATLAB is :

function c=sumab(a,b)
c=a+b;

and i call it like this :

>> sumab(2,3)

ans =

5
so i dont know where is wrong .

can help me?

tnx
Legor 30-Aug-12 2:53am    
Have you tried calling it in C# as i've mentioned?
s = a.sumab(2, 5);

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