Clear Filters
Clear Filters

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

2 views (last 30 days)
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!

Accepted Answer

Julie
Julie on 20 Aug 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.

More Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!