Need to extract a piece of data from hundreds of files

1 次查看(过去 30 天)
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!

采纳的回答

Krithika A
Krithika A 2018-7-24
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 个评论
Krithika A
Krithika A 2018-7-24
Oh sorry, I left that part in. That's just the way I want matlab to label my data. You can rename to whatever.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by