本文共 1671 字,大约阅读时间需要 5 分钟。
function main pics = dir('coil-20-proc');%list all the files in folder photo name = extractfield(pics, 'name');% extract name fields into a cell array index = ~ismember(name,[ {'.'},{'..'}]);%exclude current directory and parent directory name = name(index); arrayfun(@(x) change_name(name,x), 1:71,'UniformOutput', 0 );endfunction change_name(name, index) pic = regexp(name, strcat(strcat('__',num2str(index)),'.png$'));%find out the original gif files pic_index = cellfun(@(x) ~isempty(x), pic);% filter out gif files name = name(pic_index); before_name = cellfun(@strcat, repmat({'coil-20-proc\'},size(name)), name, 'UniformOutput', 0);% add photo prefix png_index = cellfun(@(x,y) strfind(x,y)-1, name, repmat({'.png'},size(name)), 'UniformOutput', 0); pic_name = cellfun(@(x,y) x(1:y), name, png_index, 'UniformOutput', 0 );%cell取子串 after_name = cellfun(@strcat, repmat({'result\'}, size(pic_name)), pic_name, 'UniformOutput', 0);% 加文件夹名 after_name = cellfun(@strcat, after_name, repmat({'__'}, size(after_name)), 'UniformOutput', 0);% 注意字符串包成cell degree = []; switch( floor(index / 18) ) case 0 degree = 'fourfive'; case 1 degree = 'onethreefive'; case 2 degree = 'twotwofive'; case 3 degree = 'threeonefive'; end after_name = cellfun(@strcat, after_name, repmat({degree}, size(after_name)), 'UniformOutput', 0); after_name = cellfun(@strcat, after_name, repmat({'.png'}, size(after_name)), 'UniformOutput', 0); cellfun(@movefile, before_name, after_name)% change file names end
转载地址:http://cvxdi.baihongyu.com/