I think the main problem here is that you're not closing the file. There are also some annoyances you'll run into if you're trying to set tags this way using setTag(). If you do it this way, you need to set the tags in a certain order in order for them to work right. Certain tags need to be set before others can be set. Alternatively, you can put all the tags in a struct in any order is convenient, and then you can write that tag struct to the Tiff object at once. That's how I'd do it.
This is mostly copy-pasted from another answer I posted. It's more than what you need, but it's generalized enough to cover most cases while being flexible. FWIW, the Deflate compression is lossless. Given that we're making giant DPFP TIFF files that probably nothing else can read, there's little risk in complicating the affair, but fair gains to be had over using uncompressed data. Like anything, it depends on the image content.
inpict = imread('cameraman.tif');
inpict = im2double(inpict);
tagstruct.ImageLength = sz(1);
tagstruct.ImageWidth = sz(2);
tagstruct.Compression = Tiff.Compression.AdobeDeflate;
tagstruct.SamplesPerPixel = sz(3);
tagstruct.PlanarConfiguration = Tiff.PlanarConfiguration.Chunky;
tagstruct.Photometric = Tiff.Photometric.MinIsBlack;
tagstruct.Photometric = Tiff.Photometric.RGB;
if isinteger(inpict) && inclass(1) == 'u'
tagstruct.SampleFormat = Tiff.SampleFormat.UInt;
elseif isinteger(inpict) && inclass(1) == 'i'
tagstruct.SampleFormat = Tiff.SampleFormat.Int;
tagstruct.SampleFormat = Tiff.SampleFormat.IEEEFP;
error('this demo only supports integer and float inputs')
tagstruct.BitsPerSample = 8;
tagstruct.BitsPerSample = 16;
case {'uint32','int32','single'}
tagstruct.BitsPerSample = 32;
error('LibTIFF does not support 64b outputs except for double-precision floats')
tagstruct.BitsPerSample = 64;
error('this demo only supports integer and float inputs')
tagstruct.ImageDescription = myMetaData;
newpict = imread(filename);
EDIT:
It might not be relevant here, but I forgot to mention that signed-integer outputs cannot be RGB. It's a niche concern, but this demo code doesn't check for that. I also made no accomodation for logical images. Take that FWIW.