- Call the 'cov' function on t2 and store the result.
- Call the 'cov' function again, but this time on the result from step 1.
COM: matlabObj.Feval() - works for calling one function, how would it work for calling a nested set of functions?
1 次查看(过去 30 天)
显示 更早的评论
Take this c# / .NET example of calling a Feval on "cov" for variable t2, which works great:
> t2.GetType()
[System.Double[,]]
> object results = null; matlab.Feval("cov", 1, out results, t2)
> results
object[1] { double[10, 10] { { 32.2, -34.599999999999994, 71.65, 1856.1999999999998, 94.25, 35.45, 92.2, 152.3, -138.3, 157 }, { -34.599999999999994, 2939.7999999999993, 2205.55, 18073.399999999998, -40.24999999999994, 261.15000000000003, 2120.3999999999996, 69.10000000000008, 1741.9, 3924 }, { 71.65, 2205.55, 3813.3, 15569.649999999998, 728.5, 39.14999999999998, 3730.3999999999996, 1317.1, 1380.65, 6561.5 }, { 1856.1999999999998, 18073.399999999998, 15569.649999999998, 395910.19999999995, 7004.25, 6084.450000000001, 17791.2, 13353.3, -6674.299999999999, 34322 }, { 94.25, -40.24999999999994, 728.5, 7004.25, 432.5, 61.750000000000014, 788, 729.5000000000001, -400.75, 1367.5 }, { 35.45, 261.15000000000003, 39.14999999999998, 6084.450000000001, 61.750000000000014, 123.2, 79.19999999999999, 119.8, -135.04999999999998, 189.5 }, { 92.2, 2120.3999999999996, 3730.3999999999996, 17791.2, 788, 79.19999999999999, 3677.2, 1419.8000000000002, 1159.2, 6482 }, { 152.3, 69.10000000000008, 1317.1, 13353.3, 729.5000000000001, ...
This is equivalent to calling:
cov(t2)
How would you call in c# the matlab equivalent of:
cov(cov(t2)) % ?
Obviously, something like this:
> object results = null; matlab.Feval("cov(cov)", 1, out results, t2)
System.Runtime.InteropServices.COMException: Undefined function 'cov(cov)' for input arguments of type 'double'.
+ System.RuntimeType.ForwardCallToInvokeMember(string, System.Reflection.BindingFlags, object, object[], bool[], int[], System.Type[], System.Type)
+ MLApp.MLAppClass.Feval(string, int, out object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object, object)
>
fails ... what would the syntax be to call this?
Not using .Execute or .Eval on purpose, as calling a function is way better (data does not get publicly available within the global environment, and parallelization is possible within a c# multi-threaded execution environment.
0 个评论
回答(1 个)
Vatsal
2024-5-7
Hi Andy,
To "call cov(cov(t2))" from C# using the "Feval" method, it is necessary to approach this in two steps due to "Feval" being able to call only one MATLAB function at a time. Initially, execute the inner 'cov' function and then use its output as the input for the outer 'cov' function.
Here is how you can do it:
Here is an example in C#:
// Call the inner function
object innerResult = null;
matlab.Feval("cov", 1, out innerResult, t2);
// Call the outer function using the result of the inner function
object outerResult = null;
matlab.Feval("cov", 1, out outerResult, innerResult);
I hope this helps!
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!