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 matlab.io.fits namespace path, or use the import function to add the namespace to the current import list prior to calling the function. For example:

    import matlab.io.*;
    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 https://fits.gsfc.nasa.gov/.

MATLAB uses FITS C library version 4.5.0. (since R2026a)

Before R2026a: MATLAB uses FITS C library version 4.1.0.

Before R2023a: MATLAB uses FITS C library version 3.45.

Functions

expand all

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

File Access

matlab.io.fits.closeFileClose FITS file
matlab.io.fits.createFileCreate FITS file
matlab.io.fits.deleteFileDelete FITS file
matlab.io.fits.fileModeGet I/O mode of FITS file
matlab.io.fits.fileNameGet name of FITS file
matlab.io.fits.openDiskFileOpen FITS file
matlab.io.fits.openFileOpen FITS file (extended-filename syntax)

Image Manipulation

matlab.io.fits.createImgCreate FITS image
matlab.io.fits.getImgSizeGet size of FITS image
matlab.io.fits.getImgTypeGet data type of FITS image
matlab.io.fits.insertImgInsert FITS image after current HDU
matlab.io.fits.readImgRead FITS image data
matlab.io.fits.setBscaleSet FITS image scaling
matlab.io.fits.writeImgWrite FITS image data

Keywords

matlab.io.fits.deleteKeyDelete keyword by name
matlab.io.fits.deleteRecordDelete keyword by record number
matlab.io.fits.getHdrSpaceGet number of records in header
matlab.io.fits.readCardRead header record of keyword
matlab.io.fits.readKeyRead key value
matlab.io.fits.readKeyCmplxRead key as complex scalar value
matlab.io.fits.readKeyDblRead key as double-precision value
matlab.io.fits.readKeyLongLongRead key as 64-bit integer value
matlab.io.fits.readKeyLongStrRead key as long string value
matlab.io.fits.readKeyUnitRead physical units string from keyword
matlab.io.fits.readRecordRead header record specified by number
matlab.io.fits.writeCommentWrite COMMENT keyword to current HDU
matlab.io.fits.writeDateWrite DATE keyword to current HDU
matlab.io.fits.writeHistoryWrite HISTORY keyword to current HDU
matlab.io.fits.writeKeyAdd or update keyword in current HDU
matlab.io.fits.writeKeyUnitWrite physical units string

Header Data Unit (HDU) Access

matlab.io.fits.copyHDUCopy current HDU from one file to another
matlab.io.fits.deleteHDUDelete current HDU in FITS file
matlab.io.fits.getHDUnumGet number of current HDU in FITS file
matlab.io.fits.getHDUtypeGet type of current HDU in FITS file
matlab.io.fits.getNumHDUsGet number of HDUs in FITS file
matlab.io.fits.movAbsHDUMove to absolute HDU number
matlab.io.fits.movNamHDUMove to first HDU having specific type and keyword values
matlab.io.fits.movRelHDUMove relative number of HDUs from current HDU
matlab.io.fits.writeChecksumCompute and write checksum for current HDU

Image Compression

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

ASCII and Binary Tables

matlab.io.fits.createTblCreate new ASCII or binary table extension
matlab.io.fits.insertColInsert column into table
matlab.io.fits.insertRowsInsert rows into table
matlab.io.fits.insertATblInsert ASCII table after current HDU
matlab.io.fits.insertBTblInsert binary table after current HDU
matlab.io.fits.deleteColDelete column from table
matlab.io.fits.deleteRowsDelete rows from table
matlab.io.fits.getAColParmsGet ASCII table information
matlab.io.fits.getBColParmsGet binary table information
matlab.io.fits.getColNameGet table column name
matlab.io.fits.getColTypeGet scaled column data type, repeat value, and width
matlab.io.fits.getEqColTypeGet column data type, repeat value, and width
matlab.io.fits.getNumColsGet number of columns in table
matlab.io.fits.getNumRowsGet number of rows in table
matlab.io.fits.readATblHdrRead header information from current ASCII table
matlab.io.fits.readBTblHdrRead header information from current binary table
matlab.io.fits.readColRead rows of ASCII or binary table column
matlab.io.fits.setTscaleSet table column scaling
matlab.io.fits.writeColWrite elements into ASCII or binary table column

Utilities

matlab.io.fits.getConstantValueGet numeric value of named constant
matlab.io.fits.getVersionGet revision number of CFITSIO library
matlab.io.fits.getOpenFilesGet list of open FITS files

Topics

Related Information