addition of more variable that not exist in the CSV wile using readtable
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sani
am 15 Aug. 2021
Kommentiert: Walter Roberson
am 16 Aug. 2021
Hello everyone,
I'm using readtable to read a large size CSV.
for some reasone the table is reading with an additional of 2 more columns (Var7 and Var8).
that happens even when I'm using detectimportoptions.
I'm not adding a variable at any place before, and in less heavier files the variables 7 and 8 are not exist in the table.
Is this a known error? anyone run into it and can advice how to avoid the unwanted variables?
3 Kommentare
Walter Roberson
am 15 Aug. 2021
If there are lines that end with commas, then they imply an extra (empty) variable.
Akzeptierte Antwort
Star Strider
am 15 Aug. 2021
One option is to use fileread or readcell to see if there is anything in those locations. Since most .csv files are actually Excel files (currently), using a format string as described in Create and Format Table from Text File and then suppressing the input of the last two columns by adding an asterisk to the format desciptor ('%*f%*f') is probably not possible.
.
3 Kommentare
Walter Roberson
am 16 Aug. 2021
You do not need the if . You could just use
t(:,7:end) = [];
if the width is less than 7, such as if there are only 5 variables in the table, then it would be 7:5 which would be empty, and nothing would be selected for deletion.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets 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!