f



Using matlab dll in c#

Does anyone now where I can found example code on how to use dll
objects (created in Matlab) in .NET Visual C#
0
Jakes_366 (2)
1/21/2005 10:18:01 AM
comp.soft-sys.matlab 211266 articles. 24 followers. lunamoonmoon (257) is leader. Post Follow

3 Replies
1110 Views

Similar Articles

[PageSpeed] 2

Jakes Windell wrote:
>
>
> Does anyone now where I can found example code on how to use dll
> objects (created in Matlab) in .NET Visual C#

 <http://www.codeproject.com/dotnet/matlabeng.asp>

read the part about "access with dll"
0
someone2 (821)
1/21/2005 10:53:45 AM
Below is an example that works for calling a MATLAB Compiler 4.0 (R14)
generated DLL from C#...

Copy the following code and save it as timestwo.m:


function y = timestwo(x)
y = 2*x;
H=plot(y*[1:10]);
waitfor(H);


This function multiples the input by two and then displays a line plot.

Now execute "mbuild -setup" and select your Microsoft compiler.  Generate
the shared library by executing:


mcc -B csharedlib:libtimestwo timestwo.m


Note that, in order to call the generated DLL, the DLL must reside either in
the same directory as your executable or in a directory on your system path.
For help in how to modify the system path, see:

http://www.mathworks.com/support/solutions/data/1-15ZLK.html?1-15ZLK

Also, if you move the generated DLL to another directory, be sure to also
move the associated CTF-file to the same directory.

Open Microsoft Visual Studio .NET.  Select File->New->Project.  Then select
Visual C# Applications in the left pane and Console Application in the right
pane.  Click OK and some automatically generated code will appear.  Replace
this code with:


using System;
using System.Collections;
using System.Collections.Specialized;
using System.Data;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
using System.IO;
using System.Text;
using System.Threading;

namespace TestTimesTwo
{
 class TestTimesTwo
 {
  [DllImport(@"libtimestwo.dll")]
  private static extern void libtimestwoInitialize();
  [DllImport(@"libtimestwo.dll")]
  private static extern void libtimestwoTerminate();
  [DllImport(@"libtimestwo.dll")]
  private static extern void mlfTimestwo(int num, ref IntPtr
theOutput,[In]IntPtr theInput);
  [DllImport(@"libmx.dll")]
  private static extern IntPtr mxCreateDoubleScalar([In]double value);
  [DllImport(@"libmx.dll")]
  private static extern IntPtr mxGetPr([In]IntPtr mxArray);
  [DllImport(@"mclmcrrt71.dll")]
  private static extern bool mclInitializeApplication(string options, int
count);
  [DllImport(@"mclmcrrt71.dll")]
  private static extern void mclTerminateApplication();

  [STAThread]
  static void Main(string[] args)
  {
   bool ret;
   double[] ans = new double[1];

   // Initialize libraries
   ret= mclInitializeApplication("NULL",0);
   libtimestwoInitialize();

   // Initialize arguments
   IntPtr inVal = mxCreateDoubleScalar(3);
   IntPtr outVal = IntPtr.Zero;

   // Call library function
   mlfTimestwo(1,ref outVal,inVal);

   // Get return value
   Marshal.Copy(mxGetPr(outVal),ans,0,1);

   // Print output
   Console.WriteLine("The return value is " + ans[0]);

   // Terminate libraries
   libtimestwoTerminate();
   mclTerminateApplication();
  }
 }
}



You should now be able to build the executable.

"Daniel T" <someone@microsoft.com> wrote in message
news:eef93f4.0@webx.raydaftYaTP...
> Jakes Windell wrote:
> >
> >
> > Does anyone now where I can found example code on how to use dll
> > objects (created in Matlab) in .NET Visual C#
>
>  <http://www.codeproject.com/dotnet/matlabeng.asp>
>
> read the part about "access with dll"


0
jhalbroo (2)
1/21/2005 1:26:18 PM
Hi,

There is an ebook that tells you how to work between MATLAB & C# at:
www.LePhanPublishing.com

LePhan.

wafaie wrote:
>
>
> I need to know how to use matlab dll in C#, please any one know the
> answer send me a mail and tell it to me.. thanks for help
>
>
0
LePhan (62)
3/1/2005 5:32:25 PM
Reply:

Similar Artilces:

C/C++ in matlab and matlab in C/C++ ?
Is it possible to read C/C++ code in matlab and the other way around too? Hi, as long as C or C++ are written in text files you can edit them in the matlab editor. To see the special character of C or C++ coding language, in the editor go to menus: file>preferences>Edito/Debugger>language and on popup "Language" select "C/C++". This does not allow you to run the C/C++ code, just to view it i nicer way... regards, chris saneman <asdfsdf@asd.com> wrote in message <frl846 $f8i$2@news.net.uni-c.dk>... > Is it possible to read C/C...

Conversion from MATLAB to C/C++ using MATLAB compiler
I am working on conversion of .m files to c/c++. I am using the MATLAB compiler version 3.0 and MATLAB version 6.5.1. There seem to be a few functions which do not seem to get converted. The error i got while using functions like TRAIN, NETWORK and INIT (all neural-networks related functions used in the general neural network programs, newpnn.m etc) is The MATLAB compiler does not currently support MATLAB object oriented programming and the functions TRAIN , NETWORK and INIT would produce a run-time error. Could anyone please tell me as to how i can circumnavigate this problem or solve this...

methods to call matlab in C C++ and call C C++ in matlab
Hi, I am reading the help documents about how to program matlab and C C++ together and my questions are a little bit general. It seems that are several ways to call matlab in C C++ and another several ways to call C C++ in matlab. Please correct me if I am wrong or missing something when I try to list them. To call matlab code in C C++, are there two methods available? The first one is Matlab engine and the second one is to use MATLAB Compiler mcc to create C or C++ shared libraries from your MATLAB code. To call C C++ in matlab, are there also two methods? The first one is to call funct...

Shall i use the misrosoft Visual c++ code from a m-file generated from matlab in Visual C++ with out matlab runtime environment
undefined ...

Converting Matlab code to C using Matlab Compiler
Hello All, Please can I get some guidance on how to Convert a structure from Matlab code to C code using Matlab Compiler. Kind regards Sammy ...

vectorized computation in C++ such as those in Matlab (Matlab to C++)?
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. Thus, t6 becomes a vector. t9 is an element-wise multiplication... The following code was actually converted from Matlab. If vectorized computation is not facilitated, then I have to call this function millions of times. But if vectorized computation is okay, then I can send in just a u vector with batch elements a time. I have many such code in Matlab need to be converted into C++ with vectorization. Any thoughts? Thank you! double t5, t6, t7, t9, t11, t13, t16, t20, t23, t27, t32, t34, t36, t37, t38, t42, t44, t47, t48, t51, t52, t54, t59, t60, t61, t66, t67, t69, t74, t75, t76, t81, t82, t84, t87, t105, t106, t110, t112; t5 = exp(-t * l1 - t * l2 - t * l3); t6 = t * u; t7 = mu1 * mu1; t9 = u * u; t11 = kappa * kappa; t13 = 0.1e1 / (t9 * t7 + t11); > 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. > > Thus, t6 becomes a vector. > > t9 is an element-wise multiplication... > > The following code was actually converted f...

matlab 7.1 use matlab C++ math library
I wanna use matlab C++ math library into VC++6.0, but my matlab is 7.1. if i wanna use matlab C++ math library to programme, how can i setup my VC link?? why matlab7.1 doesn't have "extern->include->cpp" file??? In using matlab C++ math library , what difference between matlab 6.X and matlab7.1??? ...

matlab beginner: calling matlab from C/C++
I'm relatively new to the world of Matlab. I want to call my matlab own code from a C/C++ program on a machine with matlab installed. Do I need to compile the matlab code using matlab compiler tool or the matlab engine is enough for this? Thanks a lot for your help On Nov 28, 10:03 am, "Paeo Campigotto" <campigo...@dit.unitn.it> wrote: > I'm relatively new to the world of Matlab. > I want to call my matlab own code from a C/C++ program on a > machine with matlab installed. > Do I need to compile the matlab code using matlab compiler > tool or the matla...

Using MatLab in C/C++
Is it possible to call MatLab or a MatLab function in C or C++? If so, where can I find info on how to do that? Mike On Feb 11, 8:57 am, "Michael Stachowsky" <mstachow...@gmail.com> wrote: > Is it possible to call MatLab or a MatLab function in C or > C++? If so, where can I find info on how to do that? > > Mike See the Matlab engine http://www.mathworks.com/access/helpdesk/help/techdoc/matlab_external/f38569.html Chris "Michael Stachowsky" <mstachowsky@gmail.com> wrote in message <fopk7d$bs2$1@fred.mathworks.com>... > Is it possibl...

Re: Using matlab dll in c#
I need to know how to use matlab dll in C#, please any one know the answer send me a mail and tell it to me.. thanks for help wafaie wrote: > I need to know how to use matlab dll in C#, please any one know the > answer send me a mail and tell it to me.. thanks for help Google returns quite a few hits for Matlab + C# -Herbert ...

converting c++ code to Matlab code using Matlab 9
im working on a project using matlab. i want to use some of the already writen codes in C++. i want to use these codes in my project rather than writing them from scratch. is there some way or a chunk of code that might convert C++ code to matlab code or a ".c" file to ".m" file. please if anyone knows do let me know at the earliest.thanks "fatima " <fatima_naseem2002@yahoo.com> wrote in message <i8ugqn$e9p$1@fred.mathworks.com>... > im working on a project using matlab. i want to use some of the already writen codes in C++. i want to use these c...

How to write a C wrapper dll to export Matlab dll functions so that LabVIEW Call Library Function Node can use it?
Hello LabView developers, &nbsp; I used LabVIEW to call Matlab m script to implement matlab MPC successfully. I wanted to use Matlab compiler to compile the matlab m script function into a c&nbsp;shared library&nbsp;.dll so that LabVIEW can call it without requiring Matlab installed on the PC. &nbsp; I used MatLab R2007b with matlab compiler. I was able to generate a C shared library dll set successfully using mcc command. &nbsp; However, from the header file, I see that the inputs and outputs of&nbsp;the function prototype&nbsp;are&nbsp;in mxArray. I need to change this data type to whatever that&nbsp;LabView Call&nbsp;Library Function Node can recognize. &nbsp; I have followed a few examples in the forum, but none of them went through. &nbsp; I use LabView 8.5. I have Microsoft Visual C++ Version 6 and Microsoft Visual Studio 2005. The compiler is in C++. Should I use a C compiler only to generate the C wrapper dll so that Labview can recognize it in the Call Library Function Node? &nbsp; If anybody has gone through this successfully, I would like to learn from you on how to do it. &nbsp; Thanks, &nbsp; Kimberly yw wrote: Hello LabView developers, &nbsp; I used LabVIEW to call Matlab m script to implement matlab MPC successfully. I wanted to use Matlab compiler to compile the matlab m script function into a c&nbsp;shared library&nbsp;.dll so that LabVIEW can call it without requiring Matlab installed ...

Cannot use multiple matlab-DLL in an C# application
Hi, there, We meet a serious problem in our c# windows form application. We use dotnetbuilder toolbox to builder 2 DLLs, which include several m-function and will be called by C# application to draw graph in figure window. There is no problem when we run each of DLL separately, but Matlab will throw an exception if we do following steps: 1. Call DLL1 to draw a figure window. 2. Close this figure window. 3. Call DLL2 to draw another figure window. 4. Click any mode toolbox button (Zoom, Pan, Rotate, etc.) in the new figure window 5. Matlab throws an exception We know .NET Builder create...

matlab beginner: calling matlab from C/C++ #2
I'm relatively new to the world of Matlab. I want to call my matlab own code from a C/C++ program on a machine with matlab installed. Do I need to compile the matlab code using matlab compiler tool or the matlab engine is enough for this? Thanks a lot for your help ...

Create (Matlab) object inside C/C++ and pass it to Matlab
I'm trying to create an object inside C++ and then pass it to Matlab via en= gPutVariable. It seems I can create a struct // Create a float array mxArray *acq_data =3D mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS); float *data =3D (float *)mxCalloc(M*N, sizeof(float)); mxSetData(acq_data, data); mxSetM(acq_data, M); mxSetN(acq_data, N); // Convert to struct const char *fieldname =3D "data"; mxArray *acq_struct =3D mxCreateStructMatrix(1,1,1, &fieldname); mxSetField(acq_struct,i,"data",acq_data); // Convert to class ?? Does it work? if (j=3D=3D1...

Parallelise matlab using MPI (C or C++)
Hello, I guess this question is more for the initiated, but I don't really know where to look so here goes. I'd like to run the simple matlab piece of code below on a supercomputer using C to lanuch mpi and then entering parameters in C which would then be taken as parameter attributes by a matlab piece of code. The parameter attributes entered into matlab would designate which core performs which computation and in that sense should speed up the operation. Example C initiates MPI and asks for say 4 workers on a single core. For each worker, see sends the worker parameter to a matlab script and the script thus runs up to a set number n where n = N/4 , so for a FOR LOOP you only solve the loop up to n for the worker. Then you need to return results and aggregate. Apparently this is doable with system function for C Can someone enlighten me of how I should go about implement this please? Here is a piece of code for which I would very much like this to work if matlabpool('size') == 0 % checking to see if my pool is already open matlabpool open 2 end parfor kay = 1:size(eige,1) % normalise eigenvector eige(kay,:) = eige(kay,:)./norm(eige(kay,:)); entrop(kay) = -(1/log(QG.numB))*sum((abs(eige(kay,:)).^2).*log(abs(eige(kay,:)).^2)) ; end where eige is a matrix and entrop a vector. Things to note: The node on the supercomputer has 16 cores and 8 workers pe...

Using MATLAB engine from languages other than C/C++?
Hello! I've been integrating my C++ programs with MATLAB, but is it possible to envoke MATLAB engine from any other object-oriented language, such as C# or Java? Thanks in advance, Domagoj Jakobovic ...

Using MATLAB in C/C++ Projects for Visualization
Hello! It's been a while since I used the Matlab Compiler the last time to use Matlab functions in C. For a new project, I'd like/have to know, if there is the possibility to use Matlab functions like "plot", "polar", "rose" and "sphere" to display data provided from C/C++. I'd like to have the Matlab code in a dll accessed and delivered with data by the C/C++ functions. This dll should do the visualization in the Matlab way. I'm curious if visualization like this is possibly and if the Matlab graphic functions like zoom, rotation, ......

Can you use zlib from Matlab, only using native Matlab code? #2
Hello, I'm trying to decompress a file using zlib, for use by my Matlab function. Currently I'm doing it by calling Python midway through my function, but I would like to make it so that I don't need to have Python installed on whatever computer I'm trying to run my function on. I was wondering if there was a way for me to use zlib just using native Matlab code. I don't know much about compression/decompression, so I'm open to any suggestions. I've been searching around for a while, and haven't found anything. Thanks very much On Tue, 05 May 2009 15:24:01 -0400, Thomas Dickinson <geoffrey.seaborn@gmail.com> wrote: > Hello, > > I'm trying to decompress a file using zlib, for use by my Matlab > function. Currently I'm doing it by calling Python midway through my > function, but I would like to make it so that I don't need to have > Python installed on whatever computer I'm trying to run my function on. > > I was wondering if there was a way for me to use zlib just using > native Matlab code. I don't know much about compression/decompression, > so I'm open to any suggestions. I've been searching around for a while, > and haven't found anything. > > Thanks very much You cuold try GUNZIP, which the doc says 'uncompresses GNU zip files', not sure if this is the same as zlib though. On May 5, 12:24=A0pm, "Thomas Dickinson" ...

C/C++ in MATALB or MATLAB in C/C++?
Hi I've been asking on the net how to use MEX properly so that I can use C/C++ in MATLAB, but information is not forthcoming. There seems to be a lot on using MATLAB in C/C++ but not the other way around. I understand Mathworks is trying very hard to sell the Matlab Compiler, but even so, why is it SO hard to get information about MEX? Or is it that I've missed something very fundamental, meaning that I'm struggling over something that is actually quite easy? Any thoughts and info would be great. Thanks BullDog BullDog wrote: > Hi > > I've been asking on the net ...

shutdown matlab.exe when matlab is not in use
Hi, I've noticed everytime I start my computer, matlab.exe starts automatically and consumes a considerable amount of memory space which slows down my computer. Is there an option to prevent this process from starting automatically each time my computer starts. I have Windows XP operating system. I have matlab 6.5. Thanks. Fenisol3 puffy_blake wrote: > Hi, > I've noticed everytime I start my computer, matlab.exe starts automatically > and consumes a considerable amount of memory space which slows down my > computer. Is there an option to prevent this process from starti...

mpeg2 read frame using C or C++ or Matlab
Is there any source/library to read single frames from MPEG-2, and save them as images? Converting the whole MPEG-2 video to other more supported formats (such as .avi) occupies too much disk space. Thanks <b83503104@yahoo.com> a �crit dans le message de news:1106506437.088185.108040@z14g2000cwz.googlegroups.com... > Is there any source/library to read single frames from MPEG-2, and save > them as images? Converting the whole MPEG-2 video to other more > supported formats (such as .avi) occupies too much disk space. > Thanks Hi, i know that manage video under lossless format can be difficult. Working in a video team, i have build a lib from VirtualDubMod source code dedicated to Mpeg file of elementary video and program stream decoding, it lead to get video frame in YUV422 raw format..... you can find it on my web site (a french site so look in the news section 2 link added today) http://berniedev.tripod.com/berniedev_site/Index.htm It's a C++ Static lib develop under VStudio 03, Look at ClassMpeg to API...And the 2 file CMPEGVideoFile .cpp and .h to sample.... good luck Have a look at this C suite: http://ffmpeg.sourceforge.net/index.php there are some example binaries that you can use/modify to do what you want. Piotr b83503104@yahoo.com wrote: > Is there any source/library to read single frames from MPEG-2, and save > them as images? Converting the whole MPEG-2 video to other more > supported formats (such as .avi) occupies ...

using the MATLAB converted C/C++ files/libraries.
Hey guys, I'm very new to MATLAB and have learned a lot in the past couple of weeks. I create a file, .m file, compile it and everything is perfect, I get all kinds of files, including a couple c/c++ files, header files, libriaries, .... What I want to know is how do I use these files for a c/c++ program, how do I implement them into a program? "Joe " <josephemassey@yahoo.com> schrieb im Newsbeitrag news:fa1h93$b4v$1@fred.mathworks.com... > Hey guys, > I'm very new to MATLAB and have learned a lot in the > past couple of weeks. I create a file,...

Using a dll from Matlab
I am trying to call a dll created by others. The program is mostly created in Fortran and have the following questions 1. How do I determine that the functions in the dll have a C interface? When I attempt to load the ibrary I get the following error: hfile =['\gtp.h'] loadlibrary('C:\Program Files\GTP\gtp.dll','hfile.h') ??? Error using ==> loadlibrary (lFullPath) Could not find file hfile.h. Error in ==> C:\MATLAB6p5\toolbox\matlab\general\loadlibrary.m On line 104 ==> header=lFullPath(header); Any help would be aprreciated ...

Web resources about - Using matlab dll in c# - comp.soft-sys.matlab

Undocumented Matlab
Undocumented, unsupported and hidden features in Matlab

Matlab Upazila - Wikipedia, the free encyclopedia
... 23°21′N 90°42.5′E  /  23.35°N 90.7083°E  / 23.35; 90.7083 Coordinates : 23°21′N 90°42.5′E  /  23.35°N 90.7083°E  / 23.35; 90.7083 Matlab ...

Open Directory - Science: Math: Software: MATLAB
The MathWorks - Developers of MATLAB, Simulink and Stateflow. Offers products for data analysis, visualization, application development, simulation, ...

MATLAB Mobile on the App Store
Read reviews, compare customer ratings, see screenshots, and learn more about MATLAB Mobile. Download MATLAB Mobile and enjoy it on your iPhone, ...

The Smart Emergency Response System Using MATLAB and Simulink - YouTube
In the aftermath of an earthquake, every second counts for disaster victims. Imagine a system that can locate people quickly and help first responders ...

The A-Z of Programming Languages: MATLAB
What prompted the development of MATLAB?

Matlab: Invalid .NET Framework. Either the specified framework was not found or is not currently supported ...
If you are trying to compile Matlab into .Net framework, you might encounter this message, even though you have the .Net framework installed ...

Matlab edges closer to electronic design automation world
Matlab, one of the world's most widely used products for algorithmic development, has long occupied its own niche far removed from EDA and hardware ...

Can I/How do I use DMTCP with a parallel pool of MATLAB workers? · Issue #223 · dmtcp/dmtcp · GitHub
dmtcp - DMTCP: Distributed MultiThreaded CheckPointing matlab -nodisplay -r "parpool('local',4); parfor i=1:10, pause(1); fprintf('%i ',i); end; ...

Using MATLAB and SDR to Reverse Engineer 433MHz Messages
... so he focused on studying the methodology and the tools available for analyzing 433MHz RF transmission. He describes the process of using MATLAB ...

Resources last updated: 3/20/2016 5:55:39 PM