MATLAB: Loading and saving sequence of files

loadmatsavesequence of files

Hello. I have number of .mat files in a same directory that has a pattern SSR(Year)(Month)(Day). The problem is not every date is included in my files. The first three files out of 55 files are as follows.
SSR20140103.mat
SSR20140207.mat % All of the files have same variable name (data).
SSR20140208.mat
I would like to load all these 55 files into my script, run the program, and save accordingly with the name azimuth_SSR(Year)(Month)(Day) .
I have checked numerous websites and links, but most of them have pattern such as file(1) – file(20) .
Thanks.
Edit 1: So far, I am considering the following code.
file_name = inputdlg('Insert the file name.');
file_name = str2num(file_name{:});
load ('', 'file_name.mat')

Best Answer

Hardcoding the list of files is just asking for trouble. One day, one of the file will be missing and the code will fail. Or one day, there'll be one more file to process, and the code won't know about it.
Asking for the name of the file to process as a string, as you suggest, is also cumbersome. The user has to make sure it is typed correctly, and if it is not in the current folder also has to type the path. At the very list, use a file open dialog, so the user just has to pick the file from the list of files that exist.
In my opinion, the most robust and user friendly approach is simply to ask the filesystem for the list of files:
filelist = dir('SSR*.mat')';
for file = filelist
filename = file.name;
ymd = regexp(filename, 'SSR(\d{4})(\d{2})(\d{2}).mat', 'tokens', 'once')
if isempty(ymd)
continue; %not an SSRyyyymmdd file
end
ymd = cellfun(@str2double, ymd);
data = load(filename);
%do something with data.(filename)
end