readtable() custom variable names

318 views (last 30 days)
I am using the below command to read a csv file into a table called T.
T = readtable("library.csv")
Now, the first row of the csv inludes the column headers, or variable names you can say. However, I want to change those variable names as I want. I have inspected readtable() documentation, but could not find the solution.
How can I do this?
Thanks.

Accepted Answer

Ameer Hamza
Ameer Hamza on 4 Apr 2020
Edited: Ameer Hamza on 4 Apr 2020
One way is to change the variable names after reading the file like this.
t = readtable("library.csv");
t.Properties.VariableNames = {'name1', 'name2'}; % names of columns
  6 Comments
Stephen23
Stephen23 on 18 May 2022
@Supriya Gain: use READCELL and WRITECELL instead.

Sign in to comment.

More Answers (1)

Steven Lord
Steven Lord on 18 May 2022
If you're using release R2020a or later I would use the renamevars function.

Community Treasure Hunt

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

Start Hunting!

Translated by