save_file='c:\Users\Public\Videos\Sample Videos\imw\imwrite\123out.gif';
path='c:\Users\Public\Videos\Sample Videos\imw\imwrite\';
path2='*.jpg';
s=strcat(path,path2);
files=dir(fullfile(s));
len=length(files);
for i=1:len
path_0=strcat(path,files(i).name);
imshow(path_0);
%M=getframe(gcf);
%nn=frame2im(M);
I=imread(path_0);
[nn,cm]=rgb2ind(I,256);
if i==1
imwrite(nn,cm,save_file,'gif','LoopCount',inf,'DelayTime',0.1);%说明loopcount只是在i==1的时候才有用
else
%[nn,cm]=rgb2ind(nn,256);
imwrite(nn,cm,save_file,'gif','WriteMode','append','DelayTime',0.1)%当i>=2的时候loopcount不起作用
end
pause(0.01)
end