CSV Variable Names truncated on 2 rows how to append
Show older comments
Hello!
I am trying to import a large number CSV files generated from another piece of software that has an unfortunate bug.
Instead of writing all the variable names (in this example 'Var') on one row, it will eventually truncate a variable name and continue on a new line. Example below:
Var1,Var2,Var3,V
ar4,Var5,Var6
Dat1,Dat2,Dat3,Dat4,Dat5,Dat6
Assuming I have no control over the data origin, how do I append/attach the 2nd row of variable names to end of the first to restore data continuity? (so that I may eventually use readtable or importdata without errors)
The row numbers for the trunkated variable names is always the same as they follow a header. It seems like for the files that I'm currently processing the truncation position is also consistant but I can't guarantee that it will stay like that forever
The end goal is to create a structure array X.Var1 ... VarN. A workaround is also acceptable.
Doing it manually is not an option as there are too many of them
Thank you!
1 Comment
Umberto Voci
on 13 Jan 2020
Edited: Umberto Voci
on 13 Jan 2020
Accepted Answer
More Answers (1)
Jyotsna Talluri
on 22 Jan 2020
0 votes
You can read the CSV files using readtable function and then you can modify the data as required
Refer to the below link
1 Comment
Umberto Voci
on 22 Jan 2020
Edited: Umberto Voci
on 22 Jan 2020
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!