Process .csv file, combine first two rows into 1 (text rows) to make them the variables
1 view (last 30 days)
Show older comments
Hello, i have the next .csv file
I don't know how to process the data, if implement the function textscan or importdata. What i would like to do is to combine the first two rows to make them one row that contains the names of the variables, for example, A1 with A2 to get the first variable: TimeSweep_time_in_h.
Thank you very much.
Juan Pablo
1 Comment
YT
on 17 Dec 2017
It would be easier if you add (a part of) the ".csv" file as attachment (using the paperclip icon).
Answers (2)
Jeremy Hughes
on 17 Dec 2017
You could try using detectImportOptions (R2016b or later) and modify the VariableUnitsLine property to bring in the second line.
opts = detectImportOptions(filename)
opts.VariableNamesLine = 1;
opts.VariableUnitsLine = 2;
T = readtable(filename,opts);
Then you can use something like strcat to put them together
T.Properties.VariableNames = strcat( T.Properties.VariableNames,'_', T.Properties.VariableUnits);
(Untested, but I think this works)
Jeremy
0 Comments
Juan Pablo Martinez Fernandez
on 19 Dec 2017
1 Comment
Jeremy Hughes
on 19 Dec 2017
It's possible with textscan, but you need to identify which columns correspond to which format specifiers and add a * to the ones you don't want. e.g. '%f%*s%f' would only import the two numeric fields and not the string in the middle.
I suggest following the same approach with import options, you can choose a subset to import with the SelectedVariableNames. The startsWith function will make matching these easy as well.
namesIDs = startsWith(opts.VariableNames,'Verlustegesamt_AnschlussiinMW');
opts.SelectedVariableNames = opts.VariableNames(namesIDs);
Jeremy
See Also
Categories
Find more on Text Data Preparation 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!