matlabcharexport-to-csvcell-arraymatlab-struct

Import a variable from .mat and export to CSV


I have a .mat file which contains a struct (called wiki),

enter image description here

in which there is a field called full_path containing data as follows:

ans = 
Columns 1 through 4

{'17/10000217_198…'}    {'48/10000548_192…'}    {'12/100012_1948-…'}    {'65/10001965_193…'}

Columns 5 through 8

{'16/10002116_197…'}    {'02/10002702_196…'}    {'41/10003541_193…'}    {'39/100039_1904-…'} 
and so on

How can I create a .csv file with the data present in the curly braces?


Solution

  • This is quite a common problem, which requires very basic functions:

    wiki = struct2array(load('wiki.mat', 'wiki'));
    fid = fopen('q52688399.csv', 'w');
    fprintf(fid,'%s\n', wiki.full_path{:});
    fclose(fid);
    

    The above will produce a ~2MB text tile containing a single column of strings.