Contenuto principale

matlab.io.fits.writeCol

Write elements into ASCII or binary table column

Syntax

matlab.io.fits.writeCol(fptr,colnum,firstrow,coldata)

Description

matlab.io.fits.writeCol(fptr,colnum,firstrow,coldata) writes elements into an ASCII or binary table extension column. When you write rows of data to a variable-length field, coldata must be a cell array.

Note

If you use this function to write complex data to a column defined by a noncomplex data type, then the function ignores the imaginary part and writes only the real part to the column. To write complex-valued data, specify a complex format for the table column by using the tform argument of the matlab.io.fits.createTbl function.

Examples

collapse all

Create a new FITS file that contains a four-column table and write data to the table.

import matlab.io.*
fptr = fits.createFile("myfile.fits");
ttype = ["Col1","Col2","Col3","Col4"];
tform = ["3A","3B","1D","1PD"];
tunit = ["m/s","kg/m^3","candela","parsec"];
ftpr = fits.createTbl(fptr,"binary",0,ttype,tform,tunit,"my-table");
fits.writeCol(fptr,1,1,['dog'; 'cat'])
fits.writeCol(fptr,2,1,[0 1 2; 3 4 5; 6 7 8; 9 10 11])
fits.writeCol(fptr,3,1,[1; 2; 3; 4])
fits.writeCol(fptr,4,1,{1;[1 2];[1 2 3];[1 2 3 4]})
fits.closeFile(fptr)

Examine the file metadata and then delete the file.

fitsdisp("myfile.fits")
HDU:  1 (Primary HDU)
	SIMPLE  =                    T / file does conform to FITS standard
	BITPIX  =                   16 / number of bits per data pixel
	NAXIS   =                    0 / number of data axes
	EXTEND  =                    T / FITS dataset may contain extensions
	COMMENT   FITS (Flexible Image Transport System) format is defined in 'Astronomy
	COMMENT   and Astrophysics', volume 376, page 359; bibcode: 2001A&A...376..359H

HDU:  2 
	XTENSION= 'BINTABLE'           / binary table extension
	BITPIX  =                    8 / 8-bit bytes
	NAXIS   =                    2 / 2-dimensional binary table
	NAXIS1  =                   22 / width of table in bytes
	NAXIS2  =                    4 / number of rows in table
	PCOUNT  =                   80 / size of special data area
	GCOUNT  =                    1 / one data group (required keyword)
	TFIELDS =                    4 / number of fields in each row
	TTYPE1  = 'Col1    '           / label for field   1
	TFORM1  = '3A      '           / data format of field: ASCII Character
	TUNIT1  = 'm/s     '           / physical unit of field
	TTYPE2  = 'Col2    '           / label for field   2
	TFORM2  = '3B      '           / data format of field: BYTE
	TUNIT2  = 'kg/m^3  '           / physical unit of field
	TTYPE3  = 'Col3    '           / label for field   3
	TFORM3  = '1D      '           / data format of field: 8-byte DOUBLE
	TUNIT3  = 'candela '           / physical unit of field
	TTYPE4  = 'Col4    '           / label for field   4
	TFORM4  = '1PD(4)  '           / data format of field: variable length array
	TUNIT4  = 'parsec  '           / physical unit of field
	EXTNAME = 'my-table'           / name of this binary table extension
delete myfile.fits

Tips

  • This function corresponds to the fits_write_col (ffpcl) function in the CFITSIO library C API.

  • To use this function, you must be familiar with the CFITSIO C interface. You can access the CFITSIO documentation at the CFITSIO website.

Extended Capabilities

expand all

Version History

expand all