Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chararrays are all mixed up #29

Open
lrq3000 opened this issue May 14, 2019 · 4 comments
Open

chararrays are all mixed up #29

lrq3000 opened this issue May 14, 2019 · 4 comments

Comments

@lrq3000
Copy link

lrq3000 commented May 14, 2019

Matlab functions returning a chararray are not properly parsed by the wrapper, they get all mixed up (all characters of 1st column, then all characters from 2nd column etc. in a single string, whereas it should return a row-wise list).

Example:

mlab.eval('res = ls')
mlab.get('res')

Returns:

'..777AAABCCCCCDDFHHIIILLLMMMMMMMMMMMMMOOOOOOOOOOOPPPPPPPPPPPPQQQQQQQQQQQQQQQQQQQQQSSSSSSTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTWWXaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccddddddddddddddddddddddddddddddddddddddddddddddddddddddeeeeeeeeeeeefffffffffffffggggggggggggggggggggggggggggggggghhhhhhhhhhhhhhhhhhiiiiiiiiiiiiiiiiiiiiiiijjjjjjjjjjjjkkklllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllll

Etc (this is an excerpt).

There is a way to workaround this by converting the output to a cellarray first using cellstr:

mlab.eval('res = cellstr(ls)')
mlab.get('res')
@mrkrd
Copy link
Owner

mrkrd commented May 15, 2019 via email

@lrq3000
Copy link
Author

lrq3000 commented Nov 21, 2019

Hello @mrkrd , thank you for your reply. Unfortunately, I need to use a matlab script to get back strings, as I have no other way to generate them without rewriting a significant portion of complex code.

But I've found a workaround: simply convert a cellarray of strings into a char(), and then in Python use the .tolist() method to properly convert it to a list of strings, and that's working flawlessly. Maybe something could be added in the readme to clue others who may have a similar need?

@lrq3000
Copy link
Author

lrq3000 commented Nov 21, 2019

To be more accurate, what I did is that I have made a matlab auxiliary script that calls the real matlab function I need to get the strings I want, and then this auxiliary script returns a char(var) where var is a cellarray of the strings I need. Let's call this auxiliary matlab script "expandhelper.m".

I then call this script from Python using:

finallistofstrings = mlab.workspace.expandhelper(listofstrings).tolist()

And that's all, they are then properly formatted.

@lrq3000
Copy link
Author

lrq3000 commented Nov 21, 2019

Update and clarification: it's a code I wrote a long time ago, I forgot some of the details. In fact, in the matlab auxiliary script, it's returning a cellstr(char(var)), so a cellstr array of the variable wrapped inside a char. So in the end, what works is returning a cellstr array, not a char array.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants