How to write multiple heterogeneous vectors data stored in a 1 row cell array into a csv file?

3 次查看(过去 30 天)
I have a cell array MyCellArray= {[1,2], [1,2,3,4], [1,2,3], [0,999, 1]}; I want to get the data in a csv file organized as the following:
1 1 1 0
2 2 2 999
3 3 1
4
How to do that?

回答(1 个)

Prannay Jain
Prannay Jain 2016-11-14
csvwrite(filename,M) does not accept cell arrays for the input matrix M. However, you could use 'xlswrite' as shown below and save the .xls file to .csv file.
>> xlswrite('xlsexample.xls',c{1}.','Sheet1','A1');
>> xlswrite('xlsexample.xls',c{2}.','Sheet1','B1');
>> xlswrite('xlsexample.xls',c{3}.','Sheet1','C1');
>> xlswrite('xlsexample.xls',c{4}.','Sheet1','D1');
I am assuming you would like to save c{1} which is a row vector into 'A1' cell of Excel as a column vector, hence I am using the transpose of c{1} = c{1}.' in 'xlswrite'.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by