-
Notifications
You must be signed in to change notification settings - Fork 23
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
Comments
On using ls:
It looks that MATLAB's ls generates 2d char array on Windows only. On
Linux it returns a char vector. For this reason, it's best to avoid
using 'ls' or your risk compatibility problems on different platforms.
Generally, I would suggest using Python for file listing/manipulation
and reduce MATLAB code to minimum, e.g., a single function with simple
input/output.
On char arrays:
It looks like a bug. At the moment matlab_wrapper converts any char
array to a string in Python. As a result is scrambles 2d MATLAB
arrays. I could accept a patch for this case, but it's still not
obvious what the corresponding data type on Python side should be:
- numpy char array, or
- list of strings?
|
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? |
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:
And that's all, they are then properly formatted. |
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. |
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:
Returns:
Etc (this is an excerpt).
There is a way to workaround this by converting the output to a cellarray first using
cellstr
:The text was updated successfully, but these errors were encountered: