how to read all files that match certain names

2 views (last 30 days)
I have files named using dates. I have a variable called 'allfiles' containing all files to access. Now I used another variable called 'datelist' containing dates list of variable 'allfiles' i.e. 2013-06-25, 2013-06-26,...
I have used this 'datelist' to separate weekdays and weekend days. Now I have trouble how to access the files of weekdays only or of weekend days only. I'm using R2014b
filenames are saved like this in the database (lots of them)
2013-06-25.mat
2013-06-26.mat
THANK YOU.

Accepted Answer

Adam
Adam on 20 Mar 2015
Whatever logic you used on your datelist variable to separate out weekend days should come with a set of indices for these. Just keep hold of these indices and use them for logical indexing into your allfiles variable, assuming they are stored in the same order.
  2 Comments
ccs
ccs on 20 Mar 2015
Edited: ccs on 20 Mar 2015
Thanks for the answer Adam. This is what I have used. Now those lists have dates only.I want to use that list (say weekend days list) to access files with those date names.
>>n=weekday(date_list);
>>weekEnds=find(n==1 | n==7);
>>myweekdays = date_list; % remove weekend days.
>>myweekdays(weekEnds) = []; % weekdays list
>>myweekEnds=datenum(date_list(weekEnds)); % weekEnds list
Path to Matfile: (not sorted into weekends and weekdays yet)
for i=1:numel(all_files)
year= datestr(date_list(i),'yyyy');
load([path '\' box '\' year '\' allfiles(i).name])
end
Adam
Adam on 20 Mar 2015
weekendsIdx = find( n == 1 | n == 7 );
weekends = all_files( weekendsIdx );
should give you the list of weekend files.
Then load those as you seem to be doing. I haven't double-checked that your file loading code is correct, but unless that is what you are asking about I'll assume it is.

Sign in to comment.

More Answers (0)

Categories

Find more on Dialog Boxes in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!