Problem concatenating a matrix of numbers with a vector of strings (column labels) using cell2mat

后端 未结 2 794
无人及你
无人及你 2020-12-06 14:10

I\'m a Mac user (10.6.8) using MATLAB to process calculation results. I output large tables of numbers to .csv files. I then use the .csv files in EXCEL. This all works f

2条回答
  •  一向
    一向 (楼主)
    2020-12-06 14:21

    You will have to handle writing the column headers and the numeric data to the file in two different ways. Outputting your cell array of strings will have to be done using the FPRINTF function, as described in this documentation for exporting cell arrays to text files. You can then output your numeric data by appending it to the file (which already contains the column headers) using the function DLMWRITE. Here's an example:

    fid = fopen('myfile.csv','w');              %# Open the file
    fprintf(fid,'%s,',columnsHeader{1:end-1});  %# Write all but the last label
    fprintf(fid,'%s\n',columnsHeader{end});     %# Write the last label and a newline
    fclose(fid);                                %# Close the file
    dlmwrite('myfile.csv',numbersTable,'-append');  %# Append your numeric data
    

提交回复
热议问题