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

2 ビュー (過去 30 日間)
Amos Gdalyahu
Amos Gdalyahu 2016 年 11 月 9 日
回答済み: Prannay Jain 2016 年 11 月 14 日
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'.

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by