readtable disfigures the CSV file header

7 ビュー (過去 30 日間)
emjey
emjey 2023 年 5 月 11 日
回答済み: Stephen23 2023 年 5 月 11 日
I need to remove the units within brackets from my CSV file, attached.
ID par1 (mol) par2 (meter^3) par3 (kg/L)
1 4 5 11
2 3 6 10
3 2 7 9
4 1 8 8
here the basic code I tried
data = readtable('headerFile.csv','ReadVariableNames', true);
headerRow = data.Properties.VariableNames
readtable however messes up the header (raplaces special characters with '_') and instead of
{'ID'} {'par_1 (mol)'} {'par_2 (meter^3)'} {'par_3 (kg/L)'}
I get
headerRow =
1×4 cell array
Columns 1 through 4
{'ID'} {'par_1_mol_'} {'par_2_meter_3_'} {'par_3_kg_L_'}
What is the best way to extract the actual header?

採用された回答

Stephen23
Stephen23 2023 年 5 月 11 日
data = readtable('headerFile.csv','ReadVariableNames', true, 'VariableNamingRule','preserve')
data = 4×4 table
ID par_1 (mol) par_2 (meter^3) par_3 (kg/L) __ ___________ _______________ ____________ 1 4 5 11 2 3 6 10 3 2 7 9 4 1 8 8

その他の回答 (1 件)

Mathieu NOE
Mathieu NOE 2023 年 5 月 11 日
hello
here you are :
headerRow = {'ID'} {'par_1 (mol)'} {'par_2 (meter^3)'} {'par_3 (kg/L)'}
data = readtable('headerFile.csv','ReadVariableNames', true,'VariableNamingRule' , 'preserve');
headerRow = data.Properties.VariableNames

カテゴリ

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

タグ

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by