Click here to Skip to main content
15,893,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need some help!
1-my Mfile have 6 nested FOR that increase the process time.so, i want to build a MEX file for its speed, but i can't find a complete tutorial about this that shows the structure of a MEX
2-I have some handle function in my Matlab code, but i don't know how can i implement them in C# !
for example, in the last FOR,a handle function created and double integral of a handle function should be computed.
3-my computation (also integration) have complex number that C# didn't support it.what can i do?
Posted
Updated 17-Mar-11 10:40am

I don't know the version of your Matlab,My version is 2009b,and my first step is building your function using matlab code,second press "deploytool" in the matlab command window,then there are many type of dll that you want to build.finally in the vs you will import this dll,and import the matlab usingspace
MathWorks.MATLAB.NET.Arrays
MathWorks.MATLAB.NET.Utility,
and before thie you should find the mwarray.dll in matlab directory.i think this will contain the structure you want;
if you need more help ,press help mwarray in matlab.
 
Share this answer
 
Comments
Member 7753662 17-Mar-11 15:22pm    
Tnx.
may version in 2010a.
In the C#, for first input argument of dblquad function (handle function) what kind of mwarray should be used?
the example below i found on the intetnet,it may offer you some help.

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Program p = new Program();
p.MatlabTest();
Console.WriteLine("press any key to exit...");
Console.ReadKey();
}
//test C# matlab invoke
private void MatlabTest()
{
Console.WriteLine("loading matlab for .NET liberary......");
DotNetTest.DotNetTestclass dt = new DotNetTest.DotNetTestclass();
Console.WriteLine("compelite......");
Console.WriteLine("-----------------------------------------------");

// multinomial
int demention = 3;
double[] dd = new double[demention];
dd[0] = 1;
dd[1] = 4;
dd[2] = 6;
//MathWorks.MATLAB.NET.Arrays.MWArray d =
//MathWorks.MATLAB.NET.Arrays.MWNumericArray.MakeSparse(
// 1, demention, MathWorks.MATLAB.NET.Arrays.MWArrayComplexity.Real, demention);
MathWorks.MATLAB.NET.Arrays.MWNumericArray d = (MathWorks.MATLAB.NET.Arrays.MWNumericArray)dd;
Console.WriteLine("begin to compute the multinomial:[{0}] ......", d.ToString());
// save the anwser
MathWorks.MATLAB.NET.Arrays.MWArray h;
//invoke matlab function to compute
h = dt.myroots(d);
// get the real part
Array real = ((MathWorks.MATLAB.NET.Arrays.MWNumericArray)h).ToArray(MathWorks.MATLAB.NET.Arrays.MWArrayComponent.Real);
string realpart = "real part list:";
foreach (double i in real)
{
realpart += i + "\t";
}
// get the imaginary part
Array imaginary = ((MathWorks.MATLAB.NET.Arrays.MWNumericArray)h).ToArray(MathWorks.MATLAB.NET.Arrays.MWArrayComponent.Imaginary);
string imaginarypart = "imaginary part list:";
foreach (double i in imaginary)
{
imaginarypart += i + "\t";
}
Console.WriteLine(realpart);
Console.WriteLine(imaginarypart);
// print results
Console.WriteLine("results:");
Console.WriteLine(h.ToString());
}
}
}
 
Share this answer
 

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