将单元格阵列导出到多列csv文件 [英] Export cell array to multi-column csv file

查看:72
本文介绍了将单元格阵列导出到多列csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是另一个关于八度的琐碎问题,希望有人可以帮助我.我有一个八度的脚本,它生成一个单元格数组.我现在想将其导出为某种形式的文本文件,可以将其导入R以进行绘图和进一步的统计分析(csv作为一种格式可能最有意义).我已经阅读了标题为"14.1.3简单文件I/O"的小节,以及关于writecsv函数的更具体的小节,但是对我来说,如何导出一个单元格数组并不明显. 这是与我的表单相同的示例数据集:

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]};

这就是test.csv的样子:

and this is what test.csv would look like:

1,5,9
2,6,10
3,7,11
4,8,12

谢谢您的建议.

推荐答案

以下命令应适用于您的测试用例:

The following command should work for your test case:

csvwrite ("data.csv", cell2mat (test')')

要了解其工作原理,请在Octave会话中运行以下命令:

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)'

这篇关于将单元格阵列导出到多列csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆