Loading multiple non-sequential .mat files to automate a code?

1 vue (au cours des 30 derniers jours)
Clarice Diebold
Clarice Diebold le 20 Août 2018
Commenté : Clarice Diebold le 21 Août 2018
Hi there! I'm very new to MatLab and am trying to figure out how to automate a code I have written. I have a set of data that is named by date and in different folders (i.e. folder names are 20171202_mic, 20171204_mic, etc. and file names things like green1_20171202_mic_data). I have seen how to automate code that has more sequential names, but I was wondering if it was possible to automate the code without the sequential naming scheme.
So far, I have named the path to the shared folder, then named the list of files with the individual foldername\name of file (i.e. '\20171202_mic\green1_20171202_16404_mic_data')
then I have for k=1:length(listoffiles)
load(fullfile(path, listoffiles{k}))
Am I very off base with this? Is there a way to do this?
Any help is very much appreciated!

Réponse acceptée

Julie
Julie le 20 Août 2018
listoffiles = dir('D:\Data\**\*.mat')
for k=1:length(listoffiles)
CurFile=listoffiles(k)
load([CurFile.folder,'\\', CurFile.name])
end
This gets you a list of all the files ending in .mat (change if your data has a different extension) and then loads them into matlab. Also replace the "D:\Data" with the path-name of the main folder.

Plus de réponses (0)

Catégories

En savoir plus sur Workspace Variables and MAT-Files 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