读取较多数据文件时注意文件名和文件读取顺序,为简单起见爱文件命名为001,002。。。数字而去命名为1,2。。。,保证读取文件顺序。由于我使用的文件对时序性有要求,就因为文件读取顺序的原因使得程序老是报错,为此找了个简单的文件批量重命名的程序
clc; clear; close all;
files = dir('*.mat');
len=length(files);
for i=1:len
oldname=files(i).name;
A=isstrprop(oldname,'digit');
B=oldname(A);
C=str2num(B);
newname=strcat('image',num2str(C,'%05d'),'.mat');
command = ['rename' 32 oldname 32 newname];
status = dos(command);
if status == 0
disp([oldname, ' 已被重命名为 ', newname])
else
disp([oldname, ' 重命名失败!'])
end
end