【问题标题】:Writing a table to csv file in Matlab在 Matlab 中将表格写入 csv 文件
【发布时间】:2019-02-02 15:50:06
【问题描述】:

我有一张桌子。细胞样本如下:

var = [1 16 18 17; 1 10 15 6; 78 10 26 43; 9 13 91 4; 1 17 81 23];

我还想将列 id 添加到如下所示:

id=[1;1;1;1;1];

现在我想通过将 id 列与 var 连接来创建一个表:

t = table(id,var)

当我尝试使用以下语法将其写入 csv 文件时:

csvwrite(t,'filename.csv','Delimiter',',')

我收到这样的错误:

Error using csvwrite 
FILENAME must be a character vector.
Error in untitled 
csvwrite(t,'filename.csv','Delimiter',',')

如何将其写入文件?

【问题讨论】:

    标签: export-to-csv matlab-table


    【解决方案1】:

    用这个代替 csvwrite:

    writetable(t,'filename.csv')  
    

    更多信息请查看this

    【讨论】:

    • writetable 和潮湿的一周一样慢(MATLAB 中面向表的所有内容都是性能不佳的案例研究 - 几乎与 xlsread() 和 xlswrite() 一样糟糕,这花 4 秒任何事情)。对于小型表 (20 x 4),writetable 只需使用 '","' 连接列、使用 '\n'fprintf 连接行,将结果变为有效,打开文件ID。 (结果将没有打开或关闭双引号,但即使 Excel 也会解析它)。
    猜你喜欢
    • 2013-01-11
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多