this is the full code with username removed
clear
path = ['C:\Users\J***\image sets\Jim\03 - ***\0\']
y = VideoWriter("newfile2.avi","Uncompressed AVI");
y.FrameRate = 3
open(y)
for n = 2:19+1
file = ['**', num2str(n) '.DCM'];
im = double(dicomread([path, file]))/2^16;
%im = imcrop(im,[1000,1000,600,600]);
imshow(im);
hold on;
text(100, 100, '*****', 'FontSize', 16, 'Color', 'white');
text(100, 200, '03 - ****\0\', 'FontSize', 16, 'Color', 'white');
text(100, 300, ['ZAxis: ', num2str(n-1), 'mm'], 'FontSize', 16, 'Color', 'white');
F = getframe(gca);
im2 = frame2im(F);
writeVideo(y,im2);
end
close(y)