Effacer les filtres
Effacer les filtres

Need to extract a piece of data from hundreds of files

1 vue (au cours des 30 derniers jours)
Stephanie M
Stephanie M le 24 Juil 2018
Commenté : Stephanie M le 24 Juil 2018
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!

Réponse acceptée

Krithika A
Krithika A le 24 Juil 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 commentaires
Krithika A
Krithika A le 24 Juil 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.
Stephanie M
Stephanie M le 24 Juil 2018
Awesome, thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by