Making a text heading to a table with numbers

2 Ansichten (letzte 30 Tage)
Taikhum Vahanvaty
Taikhum Vahanvaty am 19 Apr. 2021
Bearbeitet: David Fletcher am 19 Apr. 2021
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!

Antworten (1)

David Fletcher
David Fletcher am 19 Apr. 2021
Bearbeitet: David Fletcher am 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.

Kategorien

Mehr zu Cell Arrays finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by