Click here to Skip to main content
12,446,418 members (56,056 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# Matlab
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 :


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:

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

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

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

It seems the function in the DLL is at least called. But of course if the function expects 3 Parameters the call
a.sumab(2,5);
will produce an error. Usually in matlab if you want a return value from a function you call it
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...
  Permalink  
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160811.3 | Last Updated 28 Aug 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100