How to read a .csv file with text and numbers? How to create a for loop to do the same function for 1000 times?
Show older comments
The problem I have is that I have 1000.csv files. I named from 1.csv to 1000.csv. The first row has some text in columns 2 and 3 and numbers in columns 1,4,5,6,7. These files have 68 columns with headers starting on the second row. (In fact you can take a look at the file here http://rredc.nrel.gov/solar/old_data/nsrdb/1991-2005/tmy3/by_state_and_city.html#N). My first goal is to get the numbers from column number 32, 35, and 38 which I already did. My second goal is to get the headings for the same columns. Third, I need to get the text from column 2 and 3, numbers from column 5 and 6 FROM THE FIRST ROW OF THE FILE. Then, I have to write a new file with all the information that I subtracted from the file. The problems that I have:
1) The problem that I have is that when I tried using textscan to read the first row and the headings, I get this [], and I dont see the text or numbers. Below is what I am using to the read the file:
fid = fopen('3.csv'); %Opens the file TData = textscan(fid, '%d %s %s %f %f %f %d', 'delimiter','\t'); fclose(fid); %Closes the file
City = TData {2}; State = TData {3}; Lat = TData {5}; Lon = TData {6};
2) Can I create a for loop that will do all the process that I described above for all the 1000 files? (Take the data from the original text file and write a new file with this data)
Thank you in advance for your help,
Eric
Accepted Answer
More Answers (1)
Sean de Wolski
on 7 Jul 2011
4 Comments
X
on 7 Jul 2011
Sean de Wolski
on 7 Jul 2011
It was just a suggestion - something work trying oh well. The FAQ should help with part of your question!
X
on 8 Jul 2011
AKASH YADAV
on 8 Jan 2019
Thanks @Sean .. it worked .. :)
Categories
Find more on Data Import and Export 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!