Making a text heading to a table with numbers

6 次查看(过去 30 天)
I have a matrix A = [ 0,0,0,0; 3,4,5,6; 7,8,9,1].
I want the first row to have text headings, Like A = [ cats, dogs, ants, fish; 3, 4, 5, 6; 7, 8, 9, 1].
How can I do this? I believe I willhave to create a cell array? So if I create a new matrix with the text headings first, how can I assign the numbers to this cell array? Eventually I want to be able to write this table in an excel sheet (.csv format) and the numbers should appear as numbers only.
Thank you for your help!

回答(1 个)

David Fletcher
David Fletcher 2021-4-19
编辑:David Fletcher 2021-4-19
%Creat table with named fields
tbl=table(3,4,5,6, 'VariableNames',{'Cats', 'Dogs', 'Ants', 'Fish'})
%Add row(s)
tbl{end+1,:}=[7 ,8 , 9, 1]
As for Excel, I personally rarely touch it, but I believe you can use writetable to save a table in Excel spreadsheet format.

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by