问题
Here is another trivial question on octave that hopefully somebody can assist me with. I have a script in octave which generates a cell array. I now want to go about exporting this as some form of text file that I can import into R for plotting and further statistical analysis (csv probably makes the most sense as a format). I have read the section entitled "14.1.3 Simple File I/O" as well as the more specific section on the writecsv function however it is not obvious to me how you might export a cell array. Here is an example dataset in the same form as mine:
test = {[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]};
and this is what test.csv would look like:
1,5,9
2,6,10
3,7,11
4,8,12
Thanks for any advice.
回答1:
The following command should work for your test case:
csvwrite ("data.csv", cell2mat (test')')
To understand how it works, run the following on your Octave session:
test = {[1, 2, 3, 4],[5, 6, 7, 8],[9, 10, 11, 12]};
cell2mat (test)
test'
cell2mat (test')
cell2mat (test')'
cell2mat (test)'
来源:https://stackoverflow.com/questions/14378996/export-cell-array-to-multi-column-csv-file