MATLAB批量读取文件夹中文件,处理后放在新的文件夹中

来源:互联网 发布:nginx 外网代理 编辑:程序博客网 时间:2024/04/30 13:46
clc;clear all;close all
%%
% currPath = fileparts(mfilename('fullpath'));% 获得当前路径
currPath='C:\MATLAB\R2007b\toolbox\images\imdemos\html';
imagetype=char('.png');
nameall=strcat('*',imagetype);
A = dir(fullfile(currPath,nameall));
% 读取后A的格式为    
%                   name  -- filename
%                   date  -- modification date
%                   bytes -- number of bytes allocated to the file
%                   isdir -- 1 if name is a directory and 0 if not
%                   未知
A = struct2cell(A);
num = size(A);
for k =0:num(2)-1
    x(k+1) = A(5*k+1);% 找出name序列,x存储内容图片名字
end
%% 新建路径
newdir=char('ning_result');
mkdir(newdir) 
%% 读取得到mat文件
for k = 1:num(2)
    newpath = strcat(currPath,'\',x(k));
    temp = strcat(newpath,imagetype);
    image_name=char(x(k))
    im_temp=imread(char(newpath));
    newname=char(strcat(newdir,'\',image_name))
%    imwrite(im_temp,'dirName\图象.jpg','jpg');
    imwrite(im_temp,sprintf('%s%d%s',newname,k,imagetype));
%     imwrite(im_temp,[newdir,sprintf('%s%d%s','new',k,imagetype)]); 
end
原创粉丝点击