Azzera filtri
Azzera filtri

Importing csv files properly

2 visualizzazioni (ultimi 30 giorni)
Atanu
Atanu il 17 Lug 2021
Commentato: Star Strider il 27 Lug 2021
I am trying to import a csv file which contains 'comma'(,) inside 'quotation' marks(" ") in some cells. Here is one example.
RAB13,"RAB13, member RAS oncogene family",3.042175424,0.009699723
How can I NOT split the data at ',' if they are inside quotation? The csv is attached. Any help is appreciated!

Risposte (2)

Simon Chan
Simon Chan il 18 Lug 2021
You may use readcell and the output is a cell array.
The first row shows the header and the rest of the rows contains the requried data:
rawdata = readcell('test1.csv');
header = rawdata(1,:); % Extract the header
data = rawdata(2:end,:);

Star Strider
Star Strider il 18 Lug 2021
Import it as a table, using readtable
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/687498/test1.csv', 'VariableNamingRule','preserve')
T1 = 3×4 table
Gene.symbol Gene.title logFC adj.P.Val ___________ _____________________________________________________________ _______ _________ {'CEACAM6'} {'carcinoembryonic antigen related cell adhesion molecule 6'} 5.4297 0.0086381 {'RAB13' } {'RAB13, member RAS oncogene family' } 3.0422 0.0096997 {'TMOD3' } {'tropomodulin 3' } -1.7502 0.0096997
  2 Commenti
Peter Perkins
Peter Perkins il 27 Lug 2021
Add "TextType","string" to that readtable call and you have a winner!
Star Strider
Star Strider il 27 Lug 2021
Following up on that ...
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/687498/test1.csv', 'VariableNamingRule','preserve', 'TextType','string')
T1 = 3×4 table
Gene.symbol Gene.title logFC adj.P.Val ___________ ___________________________________________________________ _______ _________ "CEACAM6" "carcinoembryonic antigen related cell adhesion molecule 6" 5.4297 0.0086381 "RAB13" "RAB13, member RAS oncogene family" 3.0422 0.0096997 "TMOD3" "tropomodulin 3" -1.7502 0.0096997
Thanks, @Peter Perkins! I hadn’t considered that originally. It definitely improves the result!
.

Accedi per commentare.

Categorie

Scopri di più su Tables in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by