Main Content

matlab.io.fits.writeKey

Update or add new keyword into current HDU

Syntax

writeKey(fptr,keyname,value,comment)
writeKey(fptr,keyname,value,comment,decimals)

Description

writeKey(fptr,keyname,value,comment) adds a new record in the current HDU, or updates it if it already exists. comment is optional.

writeKey(fptr,keyname,value,comment,decimals) adds a new floating point keyword in the current HDU, or updates it if it already exists. You must use this syntax to write a keyword with imaginary components. decimals is ignored otherwise.

If a character value exceeds 68 characters in length, the LONGWARN convention is automatically employed.

This function corresponds to the fits_write_key (ffpky) and fits_update_key (ffuky) family of functions in the CFITSIO library C API.

Examples

import matlab.io.*
fptr = fits.createFile('myfile.fits');
fits.createImg(fptr,'byte_img',[100 200]);
fits.writeKey(fptr,'mykey1','a char value','with a comment');
fits.writeKey(fptr,'mykey2',int32(1));
fits.writeKey(fptr,'mykey3',5+7*j,'with another comment');
fits.writeKey(fptr,'mykey4',4/3,'with yet another comment',2);
fits.closeFile(fptr);
fitsdisp('myfile.fits','mode','full');