Call "log" functions from c# through COM failed with exceptions.
조회 수: 1 (최근 30일)
이전 댓글 표시
I am simply testing executing matlab functions through C# by the following,
var matlab = new MLApp.MLApp();
var n = new int[10000000];
var r = new Random();
for (int i = 0; i < 10000000; ++i)
n[i] = r.Next(1, 1000000);
var t = DateTime.Now;
for (int i = 0; i < 10000000; ++i)
{
object result = null;
matlab.Feval("log2", 1, out result, n[i]);
}
Console.WriteLine((DateTime.Now - t).TotalSeconds);
This fails with exceptions: Exception thrown: 'System.Reflection.TargetInvocationException' in mscorlib.dll Exception thrown: 'System.Runtime.InteropServices.COMException' in mscorlib.dll
However, if you test another function "randsample", it will work.
var matlab = new MLApp.MLApp();
var n = 1000;
var t = DateTime.Now;
for (int k = 0; k < 1000; ++k)
{
object result = null;
matlab.Feval("randsample", 1, out result, n, k);
}
Console.WriteLine((DateTime.Now - t).TotalSeconds);
Both are buidin math functions. I don't know why one works but the other does not. Any help is appreciated! Thanks!
댓글 수: 0
답변 (1개)
Harsh
2017년 5월 17일
Make sure the correct reference to mlapp.tlb is added in Visual Studio or any other IDE you are using. Also make sure that MATLAB is registered as a COM server. You can read more here:
Additionally make sure you are passing the correct number of input and output arguments.
The following resources may also be useful:
If the issue persists, please contact MathWorks Technical Support here: https://www.mathworks.com/support/contact_us/
Please be sure to provide a detailed description of the issue and attach any relevant files / code / examples required to investigate the issue.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Compiler SDK에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!