Rename all variables in table

2 views (last 30 days)
Suppose I have a table T about New York with variables a,b,c.... I would like to rename all variables in T as 'NYa",'NYb',.... etc without renaming variables one by one. Please advise.

Accepted Answer

Walter Roberson
Walter Roberson on 6 Jun 2018
T.Properties.VariableNames = cellfun(@(S) ['NY', S], T.Properties.VariableNames', 'Uniform', 0);
  1 Comment
Peter Perkins
Peter Perkins on 8 Jun 2018
insertBefore({'a' 'b'},1,'NY') (or strcat('NY',t.Properties.VariableNames) before R2016b-ish, I forget exactly when) would also do the trick.

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

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

Start Hunting!