Is there an example on how to use FEVAL from C# code?
5 views (last 30 days)
Show older comments
I would like to call MATLAB from my C# code and to use the FEVAL method. Do you have an example on how I can perform that?
Accepted Answer
MathWorks Support Team
on 7 Jul 2009
Below is an example showing the use of FEVAL from C# code:
add these two lines at the beginning
using System;
using System.Reflection;
// Create or get an instance of MATLAB
Type matlabType = Type.GetTypeFromProgID("Matlab.Application");
object matlab = Activator.CreateInstance(matlabType);
// Object[] parameters = new Object[] { functionName, nargout, Result, arg1, arg2, ... argN };
Object[] parameters = new Object[] { "strcat", 1, null, "Hello", " World!" };
// Make 3rd parameter (the return value) be passed by reference
ParameterModifier mods = new ParameterModifier(parameters.Length);
mods[2] = true;
try
{
// Call Feval to evaluate the result of "strcat" function
matlabType.InvokeMember("Feval",
BindingFlags.InvokeMethod,
null,
matlab,
parameters,
new ParameterModifier[] { mods },
null,
null);
// Get the return value
object Result = ((object[])parameters[2])[0];
// Print the return value
Console.WriteLine(Result);
}
catch (TargetInvocationException e)
{
Console.WriteLine(e.Message);
}
0 Comments
More Answers (0)
See Also
Categories
Find more on Programming Utilities in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!