Python to MATLAB: exporting list of strings using scipy.io

前端 未结 2 721
情话喂你
情话喂你 2021-01-11 11:47

I am trying to export a list of text strings from Python to MATLAB using scipy.io. I would like to use scipy.io because my desired .mat file should include both numerical ma

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-11 12:00

    It looks like the contents of the list are exported properly, they are just transposed and placed in a character array. You can easily convert it to the desired cell array of strings in MATLAB by transposing it and using CELLSTR, which places each row in a separate cell:

    >> my_list = ['adg';'beh';'cfi'];  %# Your example
    >> my_list = cellstr(my_list')    %'# A 3-by-1 cell array of strings
    
    my_list = 
    
        'abc'
        'def'
        'ghi'
    

    Granted, this doesn't address the more general issue of exporting data as a cell array from Python to MATLAB, but it should help with the specific problem you list above.

提交回复
热议问题