关于Matlab图像批处理问题和imwrite的用法

在网上找到的参考代码如下:看的不是很明白,请问大家我怎么样可以把处理后的图像imwrite到其它指定的文件夹了,例如我想保存到这个位置 E:\MATLAB2014\毕业设计\pictures,希望大家可以指导一下,最好给小女子解释一下代码,不胜感激
clc;clear;
pathname=uigetdir(cd,'请选择文件夹');
if pathname==0
msgbox('您没有正确选择文件夹');
return;
end
% 可以打开几乎所有的图像类型
filesbmp=ls(strcat(pathname,'*.bmp'));
filesjpg=ls(strcat(pathname,'*.jpg'));
filesjpeg=ls(strcat(pathname,'*.jpeg'));
filesgif=ls(strcat(pathname,'*.gif'));
filestif=ls(strcat(pathname,'*.tif'));
filespng=ls(strcat(pathname,'*.png'));
files=[cellstr(filesbmp);cellstr(filesjpg);...
cellstr(filesjpeg);cellstr(filesgif);...
cellstr(filestif);cellstr(filespng)];
len=length(files);
flag=[];
% 开始批量处理图像,转换格式
for ii=1:len
if strcmp(cell2mat(files(ii)),'')
continue;
end
Filesname{ii}=strcat(pathname,'\',files(ii));
page{ii}=imread(cell2mat(Filesname{ii}));
if length(size(page{ii}))==3 %图像为彩色RGB,进行转换
page1{ii}=rgb2gray(page{ii});
flag=[flag ii]; %用于存储被处理图像的在数组举证中的索引
end

end
% 批量保存转换后的图片
for ii=1:length(flag)
fname_temp=cell2mat(Filesname{flag(ii)});
dot=strfind(fname_temp,'.');
fname_temp=fname_temp(1:dot(end)-1);
FileName=strcat(fname_temp,'彩色TO灰度.jpg');
imwrite(page1{flag(ii)},FileName );
% print(gcf,'-djpeg',['E:\MATLAB2014\毕业设计\pictures\generate',FileName,'.jpeg']);
end