Getting MATLAB Numeric Arrays from a Component

I am trying to create a dll for the following code for dotnetbuilder and use the same in C#.NET.
function out = Fourier(x, n)
x_mat = cell2mat(x);
out = fft(x_mat,n);
The name of dll is "FourierTransform.dll". My C#.NET code is give below using System; using System.Collections.Generic; using System.Text;
using FourierTransform; using MathWorks.MATLAB.NET.Arrays; using MathWorks.MATLAB.NET.Utility;
namespace DLL { class Program { static void Main(string[] args) { ClassFFT obj = new ClassFFT();
MWCellArray input = null;
MWNumericArray result = null;
input = new MWCellArray(1, 3);
input[1] = new MWNumericArray(1);
input[2] = new MWNumericArray(1);
input[3] = new MWNumericArray(1);
result = (MWNumericArray)obj.FourierTransform(1, input, 1);
Double[] doubleArray = (Double[])result.ToVector(MWArrayComponent.Real);
Console.WriteLine(doubleArray);
Console.ReadKey();
}
}
}
The Visual studio gets crashed when the above code is run. Please help me if anybody knows why it is crashed...
Thanks, Srikanth

 채택된 답변

Titus Edelhofer
Titus Edelhofer 2012년 1월 13일

1 개 추천

Hi Srikanth, you are nearly done. Some slight changes: although you have only one output argument, the method will return an array. Unfortunately you can't cast that array directly but with the following changes it works:
MWArray[] result = null;
...
result = (MWArray[])obj.Fourier(1, input, 1);
MWNumericArray result1 = (MWNumericArray) result[0];
Double[] doubleArray = (Double[]) result1.ToVector(MWArrayComponent.Real);
The last two lines may be combined of course, the intermediate variable result1 is just for better reading.
Titus

댓글 수: 1

Srikanth
Srikanth 2012년 1월 13일
Hello Titus,
Thank you very much! It worked well.
Thanks,
Srikanth

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Deploy to .NET Applications Using MWArray API에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by