Search code examples
matlabcsvcell

Cell of matrices to csv matlab


I have a problem converting my results to a csv file. My cell is like this:

[1403x36 double]    [1290x36 double]    [1813x36 double]    [1363x36 double]    [1286x36 double]
[1355x36 double]    [1194x36 double]    [1130x36 double]    [1277x36 double]    [1494x36 double]
[1447x36 double]    [1455x36 double]    [1817x36 double]    [1434x36 double]    [1536x36 double]

I want my CSV file to have (rows x 36). I tried already cell2csv and i did a loop of fprint also, but neither of them worked. Thank you in advance.


Solution

  • As with the other users who have commented, it's not clear to me what the desired structure or ordering of the contents of your CSV should be, but here is an example workflow that assumes you would be comfortable first reshaping your cell array into an Q x 1 size (in column-major order), and then concatenating the contents in each cell into an Mx36 matrix.

    myCell = {rand(10,36),rand(5,36); rand(4,36),rand(7,36)};
    myCell = myCell(:);
    myMatrix = cell2mat(myCell);
    csvwrite('filename.csv',myMatrix);