Using fopen for all .CSV files in a single folder
Show older comments
I am trying to read column C from all .CSV files in a single folder (which has data in columns A-E) and merge into one single column vector. I am using the following code:
w = 1;
z = [];
D = dir('C:\xxxxx\xxxx\xxx\xx\*.csv');
%
for k = 1:length(D)
fileID = (fopen(D(k,1).name,'r');
c = textscan(fileID,'%*d%*d%d%*d%*d', 'Delimiter', ',');
x = c{1,1};
fclose(fileID);
%
for n = 1:length(x)
z(w,1) = x(n);
w = w + 1;
end
end
There seems to be a problem with the fopen command as I am not able to read any values from the file.
When I test the code in the command prompt I am able to read values, but it is not working in the script with the loop.
I am not getting any errors, just not able to read any values.
Any ideas on what the problem is? Any suggestions? Thanks
Accepted Answer
More Answers (2)
Ken Atwell
on 19 May 2015
1 vote
Image Analyst
on 18 May 2015
0 votes
Try changing 'Delimeter' to 'Delimiter'.
3 Comments
Jacee Johnson
on 18 May 2015
Image Analyst
on 18 May 2015
Why are you retyping code? You can do a copy and paste you know, which would avoid these errors. I doubt anybody will do anything more until you read this and attach a sample data file - otherwise it's just guessing, and I assume you'd prefer a tested and proven solution over a guess.
Jacee Johnson
on 18 May 2015
Categories
Find more on Low-Level File I/O 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!