Hidden away in the Tips section of the csvwrite
documentation:
csvwrite
does not accept cell arrays for the input matrixM
. To export a cell array that contains only numeric data, usecell2mat
to convert the cell array to a numeric matrix before callingcsvwrite
. To export cell arrays with mixed alphabetic and numeric data, where each cell contains a single element, you can create an Excel® spreadsheet (if your system has Excel installed) usingxlswrite
. For all other cases, you must use low-level export functions to write your data. For more information, see Export Cell Array to Text File in the MATLAB® Data Import and Export documentation.
I'd say, use xlswrite
.
If you can't use xlswrite
, it looks like you are stuck doing it manually as described on the page, Export Cell Array to Text File. Something along the lines of:
% write headers
fid = fopen('test.csv','w');
fprintf(fid,'%s,',data1{:});
fprintf(fid,'\n');
% write data...
fprintf(fid,[repmat('%d,',1,numel(data1)) '\n'],data2);
fclose(fid)