Reputation: 33
I am working in MATLAB and trying to add units to the Column headers to a table of values, e.g 'Time[s]', but this is invalid because of the []. According to everything I've found thus far has said that column headers must be valid variable names, e.g. alphanumeric and "_" only. Does anyone know of a work-around to add units to the titles that are obviously units? I would need either [] or (), / and * to cover all possible units.
Upvotes: 0
Views: 4297
Reputation: 65430
For tables it is true that the column names have to be valid variable names (as you've found) and none of the characters you've mentioned are allowed in variable names in MATLAB. If you want to include unit information with your columns, you'll want to use the VariableUnits
of the table properties to specify these.
t = table(rand(10, 1), 'VariableNames', {'Time'});
t.Properties.VariableUnits = {'sec'};
You could also modify the VariableDescriptions
.
t.Properties.VariableDescriptions = {'Time (s)'};
Then when you view the summary data, the units and your custom description will be shown.
summary(t)
%// Variables:
%//
%// Time: 10x1 double
%// Units: sec
%// Description: Time (s)
%// Values:
%//
%// min 0.11437
%// median 0.4344
%// max 0.96995
Update
If you really wanted to, you would need to use variable names that are valid but convey the units (i.e. Time_sec
)
Upvotes: 2