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

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

采纳的回答

Julie
Julie 2018-8-20
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by