How to change variable names to headings in table?

4 views (last 30 days)
I have the following table in my code:
table = table(ht,hGt,Tkt,Prt,Drt);
When the table is displayed I want each variable to be named under the following headings:
ht = "Geometric Altitude (km)"
hGt = "Geopotential Altitude (km)"
Tkt = "Temperature (K)"
Prt = "Pressure Ratio"
Drt = "Density Ratio"
What command can I use that allows me to use these heading, I haven't found one that allows me to use an invalid variable name.
Thanks, Jake

Answers (1)

Stephen23
Stephen23 on 25 Apr 2015
Edited: Stephen23 on 25 Apr 2015
Use table's optional argument VariableNames:
names = {'GeometricAltitude_km', 'GeopotentialAltitude_km', 'Temperature_K', 'PressureRatio', 'DensityRatio};
table = table(ht,hGt,Tkt,Prt,Drt, 'VariableNames',names);
Edited to remove spaces from the cell array strings.
  2 Comments
Jake Bartelme
Jake Bartelme on 25 Apr 2015
I've tried this before but when I run the code I get the following errors:
Error using matlab.internal.tableUtils.makeValidName (line 33) 'Pressure Ratio' is not a valid variable name.
Error in setVarNames (line 48) [newnames,wasMadeValid] = matlab.internal.tableUtils.makeValidName(newnames,exceptionMode); % will warn if mods are made
Error in table (line 304) t = setVarNames(t,vnames); % error if invalid, duplicate, or empty
Error in AerE161_FinalProject (line 156) table = table(ht,hGt,Tkt,Prt,Drt, 'VariableNames',names);
Stephen23
Stephen23 on 25 Apr 2015
Edited: Stephen23 on 5 May 2015
Sorry, that was my oversight. I have edited the strings to remove all space characters. All variable names have to follow these rules:

Sign in to comment.

Categories

Find more on Cell Arrays in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!