In case somebody has a similar problem, it can be solved in the following way:
% Define the output filename for the multi-page TIFF stack
outputFilename = 'yourname.tif'; % Specify your desired output filename
% Create a Tiff object for writing the stack
t = Tiff(outputFilename, 'w');
% Get the size of the Mask - type your array's name
[numRows, numCols, numSlices] = size(Mask2);
% Loop through each slice and add it to the multi-page TIFF stack
for slice = 1:numSlices
% Extract the 2D slice
sliceData = Mask2(:, :, slice);
% Write the current slice to the multi-page TIFF stack
t.setTag('Photometric', Tiff.Photometric.MinIsBlack);
t.setTag('Compression', Tiff.Compression.None);
t.setTag('BitsPerSample', 32); % Set BitsPerSample to 32 for single precision data
t.setTag('SamplesPerPixel', 1);
t.setTag('SampleFormat', Tiff.SampleFormat.IEEEFP);
t.setTag('ImageLength', numRows);
t.setTag('ImageWidth', numCols);
t.setTag('PlanarConfiguration', Tiff.PlanarConfiguration.Chunky);
t.write(sliceData);
% Add a new page to the multi-page TIFF stack
if slice ~= numSlices
t.writeDirectory();
end
end
% Close the TIFF file
t.close();
You may also need to modify the min or max values when uploading your tif to other software such as ImageJ / Fiji to properly see all objects.