在Matlab中访问指定文件夹中的图片
发布时间
阅读量:
阅读量
matlab打开指定文件夹下的图片
以下为相关代码实现:
base_path = 'F:\Postgraduate Learning\OTB\TB50\trellis\img\';
%每个文件夹下都默认含有”.”,”…”两个隐藏的系统文件夹,前者指向该文件夹,后者指向该文件夹的父文件夹
contents = dir(base_path); %dir函数的结果中前两个是 '.' 和 '..',要把这两个去掉
names = {};
for k = 1:numel(contents),
name = contents(k).name;
%any函数:检测矩阵中是否有非零元素,如果有,则返回1,否则,返回0。
%文件里可能有子文件夹,要排除掉
if ~isdir([base_path name]) && ~any(strcmp(name, {'.', '..'})),
names{end+1} = name; %#ok
end
end
img_path = strcat(base_path, names(5)); %得到的是cell类型,需要转为string类型
img_path = img_path{
全部评论 (0)
还没有任何评论哟~
