The append 'parameter seems to match what you want.
outputFileName = 'img_stack.tif' for K=1:length(img(1, 1, :)) imwrite(img(:, :, K), outputFileName, 'WriteMode', 'append'); end
EDIT: IMAGEJ has problems opening multiples saved in this way. "Compression", "nobody" solves the problem :) use:
imwrite(img(:, :, K), outputFileName, 'WriteMode', 'append', 'Compression','none');
source share