how to easily and quickly change the variable names (headers) of multiple tables
15 views (last 30 days)
I have 20 tables, let's call them A,B,C.....etc. with size of 1000 lines and 40 column.
I would like to concatenate them all in dimension 1, using function
the problem is that I must assign each table the same Headers (variable names) to each column, to be able to concanenate them all. Right now, they are all different, because the Headers were assigned by MATLAB somewhere in my code.
Right now, the code I have is
and the code above works perfectly for assigning the variable name 'Header1' to the column 1 of Table A.
However, I am pretty confident that there is a way to automate this for every case (20 tables and 40 columns), without the need to write 800 lines of code (20*40), which obviously makes no sense. Any help is appreciated.
Thank you very much,
Walter Roberson on 11 Mar 2022
A.Properties.VariableNames can be assigned a cell array of character vectors to change all of the names. This would reduce down to 20 lines.
Alternatively, table2cell all the tables, vertcat the result, cell2table with 'VariableNames' option