sabeth
sabeth

Reputation: 51

How to export csv with column headers in matlab

When I create the following table in Matlab:

Age={22,23, 25};
Name={'A', 'B', 'C'};
T = table(Age', Name');
writetable(T,'out.csv','Delimiter',',');

I would like the csv output file to have headers on the columns.

Age      Name
22       A
23       B
25       C

Upvotes: 2

Views: 3855

Answers (1)

sabeth
sabeth

Reputation: 51

After looking for days in several places, I stumbled upon this solution that does makes headers, but did not find it anywhere else, so thought to share it here.

Age={22,23, 25};
Name={'A', 'B', 'C'};
T = table(Age, Name);
T.Properties.VariableNames={'Age', 'Name'};
writetable(T,'out.csv','Delimiter',',');

Upvotes: 3

Related Questions