MATLAB Answers

how to read all files that match certain names

1 view (last 30 days)
ccs on 20 Mar 2015
Commented: Adam on 20 Mar 2015
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)


Sign in to comment.

Accepted Answer

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.


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.
>>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])
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)

Sign in to answer this question.