Search code examples
matlabmultidimensional-arrayraster

MATLAB 3D matrix save to TIFFs (2D)


In Matlab I have a 3D matrix (AxBxT), A by B data in a grid over a period of time T.

I would like to create a number of T, 2D arrays, or TIFF files (rasters) of AxB and save them using a loop with a different name.

what I done:

load matrix.mat
for i=1:T
  tiff = matrix(:, :, i);
  outputFileName = sprintf('smb%d.tiff', i);
  imwrite(tiff,outputFileName,'WriteMode', 'append')
end

but I cant make it work,

any idea/help is more than welcome


Solution

  • All you have to do is convert the matrix to a double format then, using double(). This should work:

    load matrix.mat
    matrix = double(matrix);
    for i=1:T
      tiff = matrix(:, :, i);
      outputFileName = sprintf('smb%d.tiff', i);
      imwrite(tiff,outputFileName,'WriteMode', 'append')
    end