matlab讀取文件,重命名文件,另存爲文件

clc;
clear;
rootpath='G:/picture/data1/trainbody/';
newpath='G:/picture/data1/bodypictures/';
files=dir(fullfile(rootpath));
lens=length(files);
count=1;
for i=3:lens
    file=dir([rootpath,files(i).name]);
    len=length(file);
    for j=3:len
       oldname=file(j).name;
       newname=count;
       img=imread([rootpath,files(i).name,'/',oldname]);
        % '!'的意思是調用系統函數
       %eval(['!rename',oldname,newname]);
       newfile=[newpath,num2str(count),'.png'];
       imwrite(img,newfile)
       count=count+1;
       disp(count);
    end
end
使用matlab實現文件的讀取重命名或者另存爲操作


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章