How do I get 2D c# array from MWArray?
조회 수: 10 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
Abhiram Bhanuprakash
2014년 10월 27일
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.'
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!