MATLAB: How to write cell array into a csv file

cell array to csv file

Hello Everyone, I have a cell array C where the first row is string and the remaining rows contain numbers. How do I write the variable C into a CSV file?
For example,
c = {'abc' 'def' 'ghk';[23],[24],[67];[87],[13],[999];[656],[6767],[546]};
Thanks

Best Answer

To write the data in C to a CSV file. Use “writetable” in combination with the “cell2table” function.
% Convert cell to a table and use first row as variable names
T = cell2table(c(2:end,:),'VariableNames',c(1,:))
% Write the table to a CSV file
writetable(T,'myDataFile.csv')
For more information see: