Call "log" functions from c# through COM failed with exceptions.
4 ビュー (過去 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 で Write COM Applications to Work with MATLAB についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!