writetable for a double entry table

16 views (last 30 days)
Sim
Sim on 18 Oct 2022
Answered: Kevin Holly on 18 Oct 2022
When I write a table with a double entry as a csv file....
labels_1 = {'FirstName' 'Height' 'Weight' 'BloodPressure'}
labels_1 = 1×4 cell array
{'FirstName'} {'Height'} {'Weight'} {'BloodPressure'}
labels_2 = {'Garcia' 'Johnson' 'Wu'}
labels_2 = 1×3 cell array
{'Garcia'} {'Johnson'} {'Wu'}
B = table({'Michael';'Beverly';'Alice'},...
[64;69;67],...
[119;163;133],...
[122 80; 109 77; 117 75],...
'VariableNames',labels_1,...
'RowNames',labels_2)
B = 3×4 table
FirstName Height Weight BloodPressure ___________ ______ ______ _____________ Garcia {'Michael'} 64 119 122 80 Johnson {'Beverly'} 69 163 109 77 Wu {'Alice' } 67 133 117 75
writetable(B,fullfile(path_save_table, 'B.csv'));
Unrecognized function or variable 'path_save_table'.
....the saved excel file does not show the first column on the left with the corresponding labels, i.e.:
labels_2 = {'Garcia' 'Johnson' 'Wu'}
Any suggestion in order to show the first column with the labels ?

Accepted Answer

Kevin Holly
Kevin Holly on 18 Oct 2022
writetable(B,'B.csv','WriteRowNames',true);

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!