- Try creating a method in your MATLAB class that returns an array of "MyInnerClass" objects, and then calling that method from your .NET code to retrieve the array. This way, you can have more control over how the data is converted between MATLAB and .NET.
Deploy an array with type MATLAB Class to .NET through Data API
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Matthew Trahan
am 13 Nov. 2023
Kommentiert: Matthew Trahan
am 5 Dez. 2023
I have a class with properties that look something like this:
classdef MyMatlabClass
properties
name (1,1) string
innerClass (1,:) classes.MyInnerClass
end
end
I want my innerClass to look like an array in .NET (i.e. be a MyInnerClass[] when I query it from MyMatlabClass), but I'm just getting a type of MyInnerClass (not enumerable). When using a double as the property rather than a class, I am getting a double[] and I'm able to index and access it as expected. I've been following the documentation found here ( https://www.mathworks.com/help/compiler_sdk/dotnet/deploy-matlab-classes-to-dotnetapp-using-mda.html ) to do this conversion as well as the strongly typed docs here ( https://www.mathworks.com/help/matlab/matlab_external/data-type-mappings-between-net-and-strongly-typed-matlab-code.html ). I see the limitations in the latter documentation and this use case doesn't seem to be listed there so I hope I'm just missing something.
Thank you for any help,
Matthew
0 Kommentare
Akzeptierte Antwort
SOUMNATH PAUL
am 23 Nov. 2023
Bearbeitet: SOUMNATH PAUL
am 23 Nov. 2023
To my understanding you're trying to use MATLAB classes in a .NET environment, and you want the “innerClass" property to be treated as an array in .NET.
MATLAB does not directly support converting custom classes to .NET arrays, especially when the class contains other custom classes.
Here are some suggestions to mitigate this issue:
classdef MyMatlabClass
properties
name (1,1) string
innerClass (1,:) classes.MyInnerClass
end
methods
function innerArray = getInnerClassArray(obj)
innerArray = obj.innerClass;
end
end
end
In your .NET code, you can call the “getInnerClassArray” method to obtain the array
MyMatlabClass myObject = new MyMatlabClass();
MyInnerClass[] innerArray = myObject.getInnerClassArray();
2. You can also consider implementing custom serialization methods in your MATLAB class to convert it into a format that can be easily deserialized in .NET. You would need to write methods to serialize your MATLAB class into a standard format (e.g., JSON or XML), and then deserialize it in your .NET code.
Hope it helps!
Regards,
Soumnath
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Call Web Services from MATLAB Using HTTP finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!