Adding a unit row to a table

66 Ansichten (letzte 30 Tage)
Leon am 17 Aug. 2020
Bearbeitet: Leon am 19 Aug. 2020
Below is how I normall create my table in Excel:
TT = table(Year, Month, Day, Longitude, Latitude, Oxygen, Chlorophyll_A);
writetable(TT, 'test.xlsx');
The issue is that my community wants the units to appear in a separate row, so that the final Excel file will look like this:
Row #1: Year Month Day Longitude Latitude Oxygen Chlorophyll_A
Row #2: N/A N/A N/A decimal_degrees decimal_degrees umol/kg ug/L
Row #3: 2005 3 12, -120 25 206 3.7
and so on
My question is how do I modify my above program so that I could add an extra unit row (2nd Row in the Excel file) when using writetable?
Many thanks!
  1 Kommentar
Michael Soskind
Michael Soskind am 19 Aug. 2020
Hi Leon,
Looks like this question has been discussed previously, and although there is no solution with how to truly display the variables as another row, or next to the table header row, there is a way to set the property of the values within that row. That does not help you, but that is discussed here.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Sindar am 19 Aug. 2020
% create example table
T = array2table(magic(3),"VariableNames",["a";"b";"c"]);
% define units
T.Properties.VariableUnits = ["m";"kg";"N"];
% print the variable names in the first row
% print the units in the second row
% print the data starting in the third row
  2 Kommentare
Leon am 19 Aug. 2020
Bearbeitet: Leon am 19 Aug. 2020
Awesome! Thank you so much.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)


Find more on Data Import from MATLAB 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!

Translated by