Need to extract a piece of data from hundreds of files
1 view (last 30 days)
Show older comments
Hello,
I have hundreds of files. I need a specific piece of data from each of them. I then need to insert this data into another set of files.
I know I need to use xlsread and write. My question is: is there a way to automate Matlab opening each file? It's enough files that it would take too much effort to put each file path in an array or something.
I've been reading about dir, but i'm not sure that's what I need.
Are there any resources that could help me?
Thanks!
0 Comments
Accepted Answer
Krithika A
on 24 Jul 2018
I use dir for my text files, so for me I would do this:
files = dir('file*.txt'); % Extracting all text files that start with "file", e.g., file1, file2, etc.
x = []; % Use to put entire dataset into one matrix
for q = 1:length(files);
data = importfileB(emoB(q).name, 2, 15361); % importfileB is function I created using the import tab in matlab, you might find it useful for your excel files
eval(['x',num2str(q),'=data;']) % Use this if you want each data set seperately
x_raw = [x, data(:,1)]; % Or you can use this if you'd like your entire data set in one matrix
end
For specific excel help, go here: https://uk.mathworks.com/matlabcentral/answers/222871-reading-multiple-excel-files#answer_181883
5 Comments
Krithika A
on 24 Jul 2018
Oh sorry, I left that part in. That's just the way I want matlab to label my data. You can rename to whatever.
More Answers (0)
See Also
Categories
Find more on File Operations 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!