Main Content

FITS Files

Flexible Image Transport System

Flexible Image Transport System (FITS) is an open standard defining a digital file format useful for storage, transmission, and processing of data, formatted as multidimensional arrays or tables. You can interact with FITS files in two ways:

  • The MATLAB® high-level FITS functions provide a simplified programmatic interface for reading data from FITS files and writing data from the MATLAB workspace to FITS files.

  • The MATLAB low-level FITS functions provide finer control over the reading and writing process of FITS files by providing access to more than 50 functions in the CFITSIO C library. To use these functions in MATLAB, prefix the function name with the namespace path, or use the import function to add the namespace to the current import list prior to calling the function. For example:

    fptr = fits.openFile("tst0012.fits");

    To use the MATLAB low-level FITS functions, you must be familiar with CFITSIO C API programming concepts, described at

MATLAB uses FITS C library version 4.1.0.


expand all

fitsdispDisplay FITS metadata
fitsinfoInformation about FITS file
fitsreadRead data from FITS file
fitswriteWrite image to FITS file

File Access

closeFileClose FITS file
createFileCreate FITS file
deleteFileDelete FITS file
fileModeI/O mode of FITS file
fileNameName of FITS file
openDiskFileOpen FITS file
openFileOpen FITS file (extended-filename syntax)

Image Manipulation

createImgCreate FITS image
getImgSizeSize of FITS image
getImgTypeData type of FITS image
insertImgInsert FITS image after current image
readImgRead FITS image data
setBscaleReset FITS image scaling
writeImgWrite to FITS image


deleteKeyDelete key by name
deleteRecordDelete key by record number
getHdrSpaceNumber of keywords in header
readCardHeader record of keyword
readKeyCmplxKeyword as complex scalar value
readKeyDblKeyword as double precision value
readKeyLongLongKeyword as int64
readKeyLongStrLong string value
readKeyUnitPhysical units string from keyword
readRecordHeader record specified by number
writeCommentWrite or append COMMENT keyword to CHU
writeDateWrite DATE keyword to CHU
writeHistoryWrite or append HISTORY keyword to CHU
writeKeyUpdate or add new keyword into current HDU
writeKeyUnitWrite physical units string

Header Data Unit (HDU) Access

copyHDUCopy current HDU from one file to another
deleteHDUDelete current HDU in FITS file
getHDUnumNumber of current HDU in FITS file
getHDUtypeType of current HDU
getNumHDUsTotal number of HDUs in FITS file
movAbsHDUMove to absolute HDU number
movNamHDUMove to first HDU having specific type and keyword values
movRelHDUMove relative number of HDUs from current HDU
writeChecksumCompute and write checksum for current HDU

Image Compression

imgCompressCompress HDU from one file into another
isCompressedImgDetermine if current image is compressed
setCompressionTypeSet image compression type
setHCompScaleSet scale parameter for HCOMPRESS algorithm
setHCompSmoothSet smoothing for images compressed with HCOMPRESS
setTileDimSet tile dimensions

ASCII and Binary Tables

createTblCreate new ASCII or binary table extension
insertColInsert column into table
insertRowsInsert rows into table
insertATblInsert ASCII table after current HDU
insertBTblInsert binary table after current HDU
deleteColDelete column from table
deleteRowsDelete rows from table
getAColParmsASCII table information
getBColParmsBinary table information
getColNameTable column name
getColTypeScaled column data type, repeat value, width
getEqColTypeColumn data type, repeat value, width
getNumColsNumber of columns in table
getNumRowsNumber of rows in table
readATblHdrRead header information from current ASCII table
readBTblHdrRead header information from current binary table
readColRead rows of ASCII or binary table column
setTscaleReset image scaling
writeColWrite elements into ASCII or binary table column


getConstantValueNumeric value of named constant
getVersionRevision number of the CFITSIO library
getOpenFilesList of open FITS files


Related Information