Find Header in .CSV File and Read Column
Ältere Kommentare anzeigen
I have a large number of .CSV files in one folder. These files have different columns of data. I need to locate the desired columns by matching the header(string) and read only these columns. Example:
Date Time Temp_F Temp_C Lights_ON A/C_ON
5/23/15 12:23:07 70 21 0 1
5/23/15 12:23:08 71 22 0 1
5/23/15 12:23:09 71 22 1 1
Date Time Temp_F Temp_C Temp_K Lights_ON A/C_ON
5/24/15 13:30:27 63 17 290 1 0
5/24/15 13:30:28 64 18 291 0 0
5/24/15 13:30:29 65 18 291 1 0
I'd like to read Time, Temp_C and Lights_ON from these two files.
Before, the data was the same in all the files. I knew which columns to read and which columns to skip and was using the following code:
c = textscan('%*s%s%*d%d%d%*d', 'Delimiter', ',', 'Headerlines', 1);
Now I need to sort through the headers and match the strings and only read those columns. How would I go about doing this? Can I use textscan to accomplish this? Or maybe csvread or another command? I have attached a sample .CSV file. Thanks in advance.
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 24 Mai 2015
0 Stimmen
Consider using the relatively new readtable() as that allows you to address content by column name.
1 Kommentar
Jacee Johnson
am 25 Mai 2015
Kategorien
Mehr zu Large Files and Big Data finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!