Arrays of structs should be returned as a list of the struct objects
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 32/100
Research direction
No source file or test is named. Start by reproducing the MATLAB Engine cases with a = whos and a Simulink.BusElement array, then trace the conversion and ml.get/indexing entry points. Done means struct arrays become usable Python lists of struct objects and BusElement access no longer fails.
Written by the indexing model from the issue text.
Description
Currently, using Matlab 2019a and the associated Matlab Engine.
The engine fails to convert arrays of structs, which is a known limitation. However, the equivalent of a vector in Matlab is simply a list in Python, or, for a matrix, a list of lists. Other non-struct items correctly translate this way. The struct arrays should simply pass a list of struct objects to Python (which may need further conversion to be usable).
I worked around this by checking if it is a struct with max(size) greater than 1, and if so, I convert the variable to a cell with the struct2cell property, then pull the object into Python, which pulls it in as a list of the struct objects (or list of lists). The engine should be able to do this directly, rather than having to figure out whether to do a conversion first in the Matlab workspace.
An example of such an object is the output of whos: a = whos in Matlab.
Simulink.BusElement example and different error
Also, the Simulink.BusElement object of a Simulink.Bus will be a vector (though could be size 1). It will pull the multi-dimensional struct array into an object in Python, but the .get property fails, even if accessing the keys. i.e. ml.get(BusElement[0]) fails when BusElement is the matlab object given for the Elements property of a Simulink.Bus after translation into Python. The odd thing here is this fails with a different error. There seems to be a problem with the array indexing either in the struct array object, or the get function, or both.
Note
I just happened across the get and struct2cell properties by chance after a lot of digging from a stray answer for something else. I was pulling my hair out on getting this to work. Better documentation or examples for different types would be very helpful.
- Dominant language
- Python
- Stars
- 97
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from mathworks/matlab-engine-for-python
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
-
Support sparse array Open
Difficulty 4/5 3-5 days Newbie friendliness 42/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
All issues in mathworks/matlab-engine-for-python
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
OpenHands/extensions#626 · 1 comment ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
CSCfi/sd-search-api#39 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
StevenBlack/hosts#3255 ·