Filter löschen
Filter löschen

How do I get 2D c# array from MWArray?

9 Ansichten (letzte 30 Tage)
Sharad
Sharad am 17 Aug. 2013
I have a function in matlab that takes some square matrices as arguments and returns 3 square matrices as output.I used the .Net builder NE to use my matlab algorithm in my C# project.After giving the references to the dll of the function as well as the MWArray dll in my project, I was trying to call the method( corresponding to my matlab function) associated with my new built class.
Matlab Function: function [En Et Es]=dfmpot2(Txx,Txy,Txz,Tyy,Tyz,Tzz,Bd,gob,ade,ain,azi,h)
C# method : endpublic MathWorks.MATLAB.NET.Arrays.MWArray[] dfmpot2(int numArgsOut, MathWorks.MATLAB.NET.Arrays.MWArray Txx, MathWorks.MATLAB.NET.Arrays.MWArray Txy, MathWorks.MATLAB.NET.Arrays.MWArray Txz, MathWorks.MATLAB.NET.Arrays.MWArray Tyy, MathWorks.MATLAB.NET.Arrays.MWArray Tyz, MathWorks.MATLAB.NET.Arrays.MWArray Tzz, MathWorks.MATLAB.NET.Arrays.MWArray Bd, MathWorks.MATLAB.NET.Arrays.MWArray gob, MathWorks.MATLAB.NET.Arrays.MWArray ade, MathWorks.MATLAB.NET.Arrays.MWArray ain, MathWorks.MATLAB.NET.Arrays.MWArray azi, MathWorks.MATLAB.NET.Arrays.MWArray h);
As this method returns one array( as i guessed) how do I get the three different 2D arrays? Also How do I pass 2D Arrays into the method's argument?

Antworten (1)

Abhiram Bhanuprakash
Abhiram Bhanuprakash am 27 Okt. 2014
Hi Sharad,
I think the following link would help you create and pass matrices to methods in a MATLAB generated DLL:
Specifically, see Step 7 in the above link which says:
The following is a code in C# that declares two matrices and passes them to a MATLAB function for adding.
int[,] a ={ { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; //Matrix 1
int[,] b ={ { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; //Matrix 2
MWNumericArray arr1 = a;
MWNumericArray arr2 = b;
MyMatClass obj = new MyMatClass();
MWArray result = obj.addMatrices((MWArray)arr1, (MWArray)arr2);
You can also refer to the example 'Matrix Math' in the MATLAB documentation. Assuming you are using MATLAB R2014a, the documentation is here
Refer to the 'Matrix Math' section -> Procedure -> Step 5 -> The code 'MatrixMathApp.cs' under the line 'The program listing is shown here.'

Kategorien

Mehr zu Deploy to .NET Applications Using MWArray API finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by