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!
0 个评论
采纳的回答
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
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 Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!