matlab批量读取文件夹中内容代码

clear all;
close all;
file_path = ‘B_hatchback0.9’;%输入图像文件夹路径
img_path_list = dir(strcat(file_path,’*.mat’));%dir文件夹中的所有文件或者文件夹所组成的列表,strcat为横向连接字符串。
%获取该文件夹中所有png格式的图像,形成图像的列表
my_images={};
img_num = length(img_path_list);%获取图像总数量
if img_num > 0 %有满足条件的图像
for j = 1:img_num %逐一读取图像
image_name = img_path_list(j).name;% 获取img_path_list中第j个图像的name
my_images{j} = load(strcat(file_path,image_name));
end
save(‘image_name.mat’,‘my_images’);
end

发布了6 篇原创文章 · 获赞 1 · 访问量 707

猜你喜欢

转载自blog.csdn.net/weixin_45290086/article/details/104297070