function makeavi2(stack,frames,frsize,name)

[ht wd]=size(stack(:,:,1));

movframes=figure('Units','pixels','Position',[300 300 wd*frsize ht*frsize]);


smin=min(min(min(stack)));
smax=max(max(max(stack)));

imagesc(stack(:,:,1),[smin smax]); colormap(gray);
set(gca,'Position',[0 0 1 1]);
%set(gca,'Position',[0 0 frsize frsize]);

set(gca, 'xlimmode','manual',...
'ylimmode','manual',...
'zlimmode','manual',...
'climmode','manual',...
'alimmode','manual');

hold on;
axis image;


mov = avifile(name)



for k=1:frames
imagesc(stack(:,:,k),[smin smax]); colormap(gray);

 %   set(h,'EraseMode','xor');
    F = getframe(gca);
    mov = addframe(mov,F);
end
mov = close(mov);