Changing the name of the variables in table

8 views (last 30 days)
Let us say I have an output file (called combined) which is an array so To write to a file, first I convert it into the table but now I do not know how to change the name of the variables
T = array2table(combined);
Now the variables names are combined1, combined2 and so on but I want to give it my own names like 150K, 140K etc. Could you help me with this
  1 Comment
Shelender Kumar
Shelender Kumar on 3 Nov 2018
I did use
and it worked

Sign in to comment.

Accepted Answer

Caglar on 2 Nov 2018
Edited: Caglar on 2 Nov 2018
You can do that on initialization,
or after creation,
Note that, sadly, Matlab does not let you define variable names before you put at least one row of data.
Error using table (line 307)
The VariableNames property must contain one name for each variable in the table.
Peter Perkins
Peter Perkins on 6 Nov 2018
Shelender, array2table allows you to provide var names if you don't want the defaults. See the doc.
Caglar, the reason why
errors is because you are providing a name but no variable. You can't name something that isn't there, and there's a difference between "has no rows" and "isn't there at all". If you want a table with no rows, one variable, and a specific name, do something like this
or in recent versions (R2018a and later, IIRC), this
table('Size',[0,1],'VariableTypes',{'double'}, ,'VariableNames',{'Test'})

Sign in to comment.

More Answers (1)

awezmm on 2 Nov 2018
Edited: awezmm on 2 Nov 2018
I think you can do something like: T.Properties.VariableNames = {'newname1' 'newname2'}
awezmm on 2 Nov 2018
The issue is that you cant start variable names with numbers. You can have to some sort of string at the beginning. Maybe you can do 'Resolution_146k' or give some other title so it describes it well

Sign in to comment.


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!