Send .NET class instance to MATLAB function
8 次查看(过去 30 天)
显示 更早的评论
Hi all,
Here is what i want to do: I'm in C# and I have a compiled MATLAB dll for .NET via the Compiler SDK.
Here the C# code:
private DelegateTest.Class1 _delegate = new DelegateTest.Class1();
// creates a class instance and sends it to my MATLAB function
private void btnRun_Click(object sender, RoutedEventArgs e)
{
try
{
MyThing _thing = new MyThing();
MWObjectArray instanceWrapper = new MWObjectArray(_thing);
MWArray[] result = new MWArray[2];
result = (MWArray[])_delegate.DelegateTest(2, instanceWrapper);
foreach (MWArray item in result)
Console.WriteLine(item);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
// A Test Class which creates a Value
public class MyThing
{
public int ValueCreator()
{
return 42;
}
}
Here is my MATLAB function:
function [output1, output2] = DelegateTest(instance)
try
if isa(instance, 'ExecuteMatlabScriptInCSharo.MyThing')
output1 = 'Correct Type';
else
output1 = 'Wrong Type';
end
result = instance.ValueAusdenker();
catch ex
output2 = getReport(ex);
return
end
output2 = result;
end
Here is the output of the result after i execute it:
- [0] {Correct Type} MathWorks.MATLAB.NET.Arrays.MWArray {MathWorks.MATLAB.NET.Arrays.MWCharArray}
- [1] {Error using DelegateTest (line 9)Message: Object does not match target type. Source: mscorlib HelpLink: } MathWorks.MATLAB.NET.Arrays.MWArray {MathWorks.MATLAB.NET.Arrays.MWCharArray}
Anyone has an idea how this is going to work? Or is it simply not possible?
Thanks!
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!