自动命名文件序列名称_git


clc;clear;
if ~exist([pwd,'\','data'],'file')
mkdir([pwd,'\','data']);
end

temp=rand(1,100);
file=dir(['.\data\*.mat']);
fileNum=length(file);
if ~isempty(file)
fileNameEnd=file(fileNum).name;
numIdx=isstrprop(fileNameEnd,'digit');
nameNum=str2num(fileNameEnd(numIdx));%转换成数值
else
nameNum=0;
fileNum=0;
end
if nameNum>fileNum
filename = sprintf('temp%.4i.mat',nameNum+1);
else
for k = 1:1000
if ~exist(fullfile('.\data\',sprintf('temp%.4i.mat',k)),'file')
filename = sprintf('temp%.4i.mat',k);
break;
else
filename = sprintf('temp%.4i.mat',fileNum+1);
break;
end
end
end
save(['.\data\',filename],'temp')