Making a text heading to a table with numbers

6 views (last 30 days)
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!

Answers (1)

David Fletcher
David Fletcher on 19 Apr 2021
Edited: David Fletcher on 19 Apr 2021
%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.

Categories

Find more on Tables in Help Center and File Exchange

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!