473,756 Members | 2,977 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

calling matlab function in c#

suppose a simple matlab function
//add.m
function result=add(left ,right)
result=left + right;

//end of add.m

use matlab comtool to encapsulate the function in fun.dll
and then use it in c#.net

i create a c# web service project to call
the matlab function add

but the function declaration has changed:
//create a instance;
fun.funClass st=new fun.funClass();

when i want to write st.add(paramete rs)

the declaration is
void add(int nargout,ref object,object,o bject)

which in matlab there're only two (left and right)

Could anyone please tell what's the meaning of int nargout and ref object?
And how to call the function add correctly?
Mar 20 '07 #1
2 5315
bob
Hi,
my guess is
nargout is number of output arguments
ref object will hold the result
the two 'val' objects are the input parameters
So I would be looking for C# code something like
object myResult;
int num1 =5;
int num2 =6;
st.add(1,myResu lt,num1,num2)
ie the following c# is similar in intent
private void button1_Click(o bject sender, EventArgs e)

{

int x = 5;

int y = 6;

object myResult;

myResult = new object();

Addem(ref myResult,x,y);

int z;

if( int.TryParse(my Result.ToString (),out z))

MessageBox.Show (" Result is " + z.ToString());

}

private void Addem(ref object myResult, int x, int y)

{

myResult = x + y;

}

HTH

bob
"zipls" <zi***@163.comw rote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
suppose a simple matlab function
//add.m
function result=add(left ,right)
result=left + right;

//end of add.m

use matlab comtool to encapsulate the function in fun.dll
and then use it in c#.net

i create a c# web service project to call
the matlab function add

but the function declaration has changed:
//create a instance;
fun.funClass st=new fun.funClass();

when i want to write st.add(paramete rs)

the declaration is
void add(int nargout,ref object,object,o bject)

which in matlab there're only two (left and right)

Could anyone please tell what's the meaning of int nargout and ref object?
And how to call the function add correctly?


Mar 20 '07 #2
hi,bob!
the sol. is exactly what you've described
thanks a lot ^_^


"bob" <bo*@nowhere.co mдÈëÏûÏ¢ÐÂÎÅ:O d************** @TK2MSFTNGP05.p hx.gbl...
Hi,
my guess is
nargout is number of output arguments
ref object will hold the result
the two 'val' objects are the input parameters
So I would be looking for C# code something like
object myResult;
int num1 =5;
int num2 =6;
st.add(1,myResu lt,num1,num2)
ie the following c# is similar in intent
private void button1_Click(o bject sender, EventArgs e)

{

int x = 5;

int y = 6;

object myResult;

myResult = new object();

Addem(ref myResult,x,y);

int z;

if( int.TryParse(my Result.ToString (),out z))

MessageBox.Show (" Result is " + z.ToString());

}

private void Addem(ref object myResult, int x, int y)

{

myResult = x + y;

}

HTH

bob
"zipls" <zi***@163.comw rote in message
news:%2******** ********@TK2MSF TNGP05.phx.gbl. ..
>suppose a simple matlab function
//add.m
function result=add(left ,right)
result=left + right;

//end of add.m

use matlab comtool to encapsulate the function in fun.dll
and then use it in c#.net

i create a c# web service project to call
the matlab function add

but the function declaration has changed:
//create a instance;
fun.funClass st=new fun.funClass();

when i want to write st.add(paramete rs)

the declaration is
void add(int nargout,ref object,object,o bject)

which in matlab there're only two (left and right)

Could anyone please tell what's the meaning of int nargout and ref
object?
And how to call the function add correctly?




Mar 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1417
by: Paul McGuire | last post by:
I've spent the past day or so working through the various complexities in calling Matlab routines from Python (please do not reply with suggestions to use Numpy/Scipy/etc. - our customer is using Matlab, and I needed to learn how to access it through COM). Matlab's COM API is actually pretty clean/simple, but there are a few wrinkles, some undocumented "magic strings", and some odd surprises. Also, the Matlab COM API was designed for...
3
4005
by: Mohammed Smadi | last post by:
Hi; Does anyone know if we can call matlab for a python or bash script while feeding the matlab script some command line arguments? I have an interactive matlab script which i want to automate by feeding the args from a script. I know this is probably more suitable to a matlab group but any ideas will be appreciated.
9
5296
by: Carl | last post by:
I am desperately looking for a way to call Python from Matlab. I have become used to Python's rich syntax and large number of libraries, and feel ridiculously clumsy being stuck with Matlab's rather restricted facilities for doing other things than standard mathematical work. Does anyone know of good techniques (or readily available software) for achieving a cross-language support between Python and Matlab? Carl
3
27247
by: Ajith Menon | last post by:
Do any body know how to use the functions available in the MATLAB using C#? ( To be specific, functions COHERE used to find Coherence and TFE to calculate Transfer function are needed. These functions are available in the MATLAB SP toolbox) These functions require input waveforms X and Y, which is nothing but two array of samples (datatype=double).
1
1082
by: eric_jin | last post by:
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
2
2752
by: eric_jin | last post by:
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
4
13752
by: itcecsa | last post by:
Hi, I am implementing a small Python project, what I am going to do is to open Matlab and run some M-files, and get some output from Matlab command prompt. I have no idea how to open Matlab from Python! Any suggestions would be appriciated!
0
1641
by: rperera | last post by:
1. I want to call a matlab function that my colleague did in Matlab from Python E.g >>matlab.DetermineOutputValues(text,ArrayOfValues) My input is text, and ArrayOfValues is the value calculated and passed from MatLab There is a module called pymat and in addition there is a mlabwrap. I have not seen one simple example that illustrates what I am trying to do
1
4630
by: sanctus | last post by:
I have a Matlab code which works fine in windows. Now I installed Xubuntu (because this way I have admin rights(=root) which I don't have on windows) and want to use the same code. To be able to use the C-code you have to compile it from Matlab comand line with the comand mex myfile.c where before with mex -setup you define which compiler to use, the only choice I had was gcc (version 4.something). Now if I compile I get the following...
14
3143
by: Luna Moon | last post by:
Dear all, Can C++/STL/Boost do the vectorized calculation as those in Matlab? For example, in the following code, what I really want to do is to send in a vector of u's. All other parameters such as t, l1, l2, l3, etc. are scalars... But u is a vector.
0
9456
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
9846
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9713
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7248
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6534
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5142
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5304
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3806
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3359
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.