Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Homework 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 2:31am
Edited 28-Aug-12 4: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 at 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 at 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
0 OriginalGriff 250
1 Sergey Alexandrovich Kryukov 204
2 PIEBALDconsult 180
3 Suvendu Shekhar Giri 115
4 Peter Leow 100
0 Sergey Alexandrovich Kryukov 6,434
1 OriginalGriff 6,033
2 Peter Leow 2,534
3 Maciej Los 2,268
4 Abhinav S 2,264


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 28 Aug 2012
Copyright © CodeProject, 1999-2015
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