Involving uncommon functions: dir, strcat, variable name. name handle
file_path1 = '空间标定2\'; %被改图片位置
file_path2 = '重命名\'; %改名后图片位置
img_path_list = dir(strcat(file_path1, '*.bmp'));
%获取该文件夹中所有bmp格式的图像,strcat:串联字符串;dir:列出文件夹内容
img_num = length(img_path_list);%获取图像总数量
for j = 1 : img_num %逐一读取图像
image_name_old = img_path_list(j).name;% 图像名
image_name_new = strcat('imag', num2str(j), '.bmp');% 新图像名
image = imread(strcat(file_path1, image_name_old));% 暂存原图像数据
imwrite(image,strcat(file_path2, image_name_new));% 将新图像吗赋予原数据
end
The picture is changed from 1.bmp, 2.bmp... to imag1.bmp, imag2.bmp...