Loading multiple files with similar filenames
3 次查看(过去 30 天)
显示 更早的评论
(Sorry for asking another question so soon!)
I'm working on loading 8 files with similar names from one directory into a for loop which grabs data from each of them and then resaves them as one file.
Example
%Open directory
files = dir(uigetdir,'.mat*')
%Run this through all of the files in the directory
for i= 1:numel(files)
%load one of the files
load files(i)
%Determine information from the files
fileName=files(i).name;
a=regexp(fileName,'_','split')
experimentName = a{2}
participantName = a{3}
block=regexp(a{4},'\d*')
type = a{5}
%Load other files which have similar information to the previous file
for i = numel(files)
if regexp(fileName, 'experimentName') > 0
load files(i)
%run code on all 8 files in a for loop
for n=1:8
end
%save new information
end
%re-run on next set of 8 similar files for 200+ sets of data
I just feel like I'm going about loading these in all the wrong way. I think I may be setting myself up to have things rerun over themselves way more than they need to.
Is there a better way for me to load all 8 files with a similar name at once, such that when I finish processing them MATLAB knows to grab a different set that does not repeat any of the files from the previous set?
1 个评论
Jan
2013-6-10
I do not understand the question. Do you mean "load(files(i).name)" insteda of "load files(i)"? "for i = numel(files)" is the same as "i = numel(files)".
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!