readtable() custom variable names

152 ビュー (過去 30 日間)
Muhammed Yusuf Aksel
Muhammed Yusuf Aksel 2020 年 4 月 4 日
コメント済み: Stephen23 2022 年 5 月 18 日
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.

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 4 日
編集済み: Ameer Hamza 2020 年 4 月 4 日
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 件のコメント
Walter Roberson
Walter Roberson 2022 年 5 月 18 日
table() objects must have unique names for each variable. It is not possible to create a table() object which does not have variable names.
You can readtable() and pass VariableNames at the time of reading, thereby giving some name of your choice.
You can skip a header by using HeaderLines, 1 and ReadVariableNames, false
Stephen23
Stephen23 2022 年 5 月 18 日
@Supriya Gain: use READCELL and WRITECELL instead.

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2022 年 5 月 18 日
If you're using release R2020a or later I would use the renamevars function.

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by