Call "log" functions from c# through COM failed with exceptions.

1 vue (au cours des 30 derniers jours)
Zheng Chen
Zheng Chen le 9 Mai 2017
Réponse apportée : Harsh le 17 Mai 2017
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!

Réponses (1)

Harsh
Harsh le 17 Mai 2017
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.

Catégories

En savoir plus sur MATLAB Compiler SDK dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by