How to read an excel /csv files with columns that have both text and numbers?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SnooptheEngineer
am 1 Jul. 2024
Bearbeitet: Stephen23
am 1 Jul. 2024
Everytime I try to use readcell , readtable.. I get one or alll of the following problems:
- Numeric columns get merged into one cell array ex : {1.5,2.5} vs them being in two unique cells
- Additional columns that dont exist in my csv/xlsx files with 1x1 missing filled in
- Nan for string entries
I saw online that a column with text and numeric values dont mix well. Anyone have any suggestions?
I am also trying to find a specific string value index (xdist_mm,Power_watts) for each file to then import the data under each of these headers into a seperate array for analysis. I tried strfind and contains without much sucess)
Thank you
0 Kommentare
Akzeptierte Antwort
Stephen23
am 1 Jul. 2024
Bearbeitet: Stephen23
am 1 Jul. 2024
fnm = 'sample.csv';
tmp = readcell(fnm, 'Delimiter',',');
idx = cellfun(@ischar,tmp(:,1));
assert(all(diff(idx)<1))
nhl = nnz(idx)-1;
tbl = readtable(fnm, 'Delimiter',',', 'NumHeaderLines',nhl)
hdr = cell2struct(tmp(1:nhl,2),tmp(1:nhl,1))
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!