将带有标题的新列添加到csv Matlab [英] Add new column with header to csv Matlab
本文介绍了将带有标题的新列添加到csv Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有列标题(字符串)和数据的csv文件.然后,我想添加一个具有特定标头'My new header'
的新列,并将数据存储在一个名为myNewData
的100x1双变量中.如何添加标题为'My new header'
且列值为myNewData
的新列?
I have an csv file with column headers (strings) and data. I then want to add a new column with a specific header 'My new header'
and data is stored in a 100x1 double variable called myNewData
. How I can add a new column with header 'My new header'
and values of the column be myNewData
?
推荐答案
我能够使用Matlab中的表,仅用三行代码来做到这一点,如下所示:
I was able to do this using tables in Matlab in just three lines of code as shown below:
table = readtable('myfile.csv','Delimiter',',');
table.class = newcol; %where class is the name of the header of the new column and newcol is a variable which has my new column data
writetable(table,'myfilenew.csv','Delimiter',',','QuoteStrings',false)
这篇关于将带有标题的新列添加到csv Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文