Need to extract a piece of data from hundreds of files

1 回表示 (過去 30 日間)
Stephanie M
Stephanie M 2018 年 7 月 24 日
コメント済み: Stephanie M 2018 年 7 月 24 日
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.
Stephanie M
Stephanie M 2018 年 7 月 24 日
Awesome, thanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by