'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
使用方法の詳細については、正規表現を参照してください。また、
uigetfileを置き換えるuipickfilesに興味があるかもしれません。