Похоже, я неправильно понял, что вы имели в виду под 'file_1', 'file_2' - я думал, что числа 1 и 2 имеют какое-то значение.
oldFileName = 'something_2010_03_03.csv';
%# extract the date (it's returned in a cell array
theDate = regexp(oldFileName,'(\d{4}_\d{2}_\d{2})','match');
newFileName = sprintf('newfile_%s.xls',theDate{1});
Старая версия с пояснениями
Я предполагаю, что дата во всех ваших файлах одинакова. Таким образом, ваша программа будет идти
%# load the files, put the names into a cell array
fileNames = {'file_1_2010_03_03.csv','file_2_2010_03_03.csv','file_3_2010_03_03.csv'};
%# parse the file names for the number and the date
%# This expression looks for the n-digit number (1,2, or 3 in your case) and puts
%# it into the field 'number' in the output structure, and it looks for the date
%# and puts it into the field 'date' in the output structure
%# Specifically, \d finds digits, \d+ finds one or several digits, _\d+_
%# finds one or several digits that are preceded and followed by an underscore
%# _(?<number>\d+)_ finds one or several digits that are preceded and follewed
%# by an underscore and puts them (as a string) into the field 'number' in the
%# output structure. The date part is similar, except that regexp looks for
%# specific numbers of digits
tmp = regexp(fileNames,'_(?<number>\d+)_(?<date>\d{4}_\d{2}_\d{2})','names');
nameStruct = cat(1,tmp{:}); %# regexp returns a cell array. Catenate for ease of use
%# maybe you want to loop, or maybe not (it's not quite clear from the question), but
%# here's how you'd do with a loop. Anyway, since the information about the filenames
%# is conveniently stored in nameStruct, you can access it any way you want.
for iFile =1:nFiles
%# do some processing, get the matrix M
%# and create the output file name
outputFileX = sprintf('newfileX_%s_%s.xls',nameStruct(iFile).number,nameStruct(iFile).date);
%# and save
xlswrite(outputFileX,M)
end
См. регулярные выражения для более подробной информации о том, как их использовать. Кроме того, вы можете быть заинтересованы в
uipickfiles для замены uigetfile.