Click here to Skip to main content
15,881,139 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i want to call function in matlab from c# inside for loop using com component
when i tried it i had this exception

Invalid callee. (Exception from HRESULT: 0x80020010 (DISP_E_BADCALLEE))

this is the code
C#
   public void Start()
        {
            var activationContext = Type.GetTypeFromProgID("matlab.application.single");
            var matlab = (MLApp.MLApp)Activator.CreateInstance(activationContext);
            matlab.Visible = 0;
            int index = 0;
            var feture = new double[10][];
            for (int j = 1; j < 8; j++)
            {
                object result1;
                string name = @"C:\Users\Eng\Documents\Visual Studio 2010\Projects\FinalProject\FinalProject\Matlab\" +
                              j + ".JPG";
                matlab.Feval("WBC_SegProposed", 6, out result1, name, 0, j);
                var res = (Array) result1;
                var myEnumerator = res.GetEnumerator();
                myEnumerator.MoveNext();
                var length = (double) myEnumerator.Current;
                var len = (int) length;
                myEnumerator.MoveNext();
                var area = (double[,]) myEnumerator.Current;
                myEnumerator.MoveNext();
                var perimeter = (double[,]) myEnumerator.Current;
                myEnumerator.MoveNext();
                var compactness = (double[,]) myEnumerator.Current;
                myEnumerator.MoveNext();
                var circularity = (double[,]) myEnumerator.Current;
                myEnumerator.MoveNext();
                var names = (object[,]) myEnumerator.Current;
}
}

the exception was for this instruction " matlab.Feval("WBC_SegProposed", 6, out result1, name, 0, j);"
what should i do ?
Posted
Comments
Matt T Heffron 11-Jul-14 12:55pm    
Did it fail on the FIRST time through the loop? Or the second? Or n-th?
Esraa Saady 11-Jul-14 15:23pm    
thanks for reply..on the second time
George Jonsson 14-Jul-14 23:18pm    
What is the result if you remove all code in the loop after this line?
matlab.Feval("WBC_SegProposed", 6, out result1, name, 0, j);

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900