Matlab read FITS image stacks

In Matlab, fitsread is used to read specific frame(s) from a FITS file. That is, you can read frames one at a time from a large multi-frame FITS file in MATLAB. This avoids overwhelming RAM or taking an excessive time to load just one or a few image frames from a FITS file.

Example: sequentially read and plot each frame of a 4096-frame FITS file, with each frame being 256x256 pixels.

for i = 1:4096
  currFrame = fitsread('myFile.fits', PixelRegion={[1 256],[1 256],i});
  imagesc(currFrame)
  pause(0.05)
end

GNU Octave FITS reading is done with the fits package with different syntax.


Related: read FITS image stack in Python