Trouble getting a value of a keyword in a FITS file.

3 views (last 30 days)
I have a FITS file named sun.fits. With fitsinfo('sun.fits'), the structure in the image below is output.
The Image header at the end contains the structure seen in the image below.
There is a specific keyword, 'EXPTIME', in the Keywords header at the end that contains a value that I want, as seen in the third image below.
fitsread('sun.fits', image) just images the data encoded in the DataType of the second image. I tried to find a way to access that specific keyword that I need in a script but couldn't find any. Of course, I can just double click on the Keywords and just find and see the value from there but I want to write code that returns it when I know the keyword that I'm looking for.
Thanks in advance, Chris

Accepted Answer

Walter Roberson
Walter Roberson on 5 Feb 2018
info = fitsinfo('sun.fits');
keywords = info.Keywords;
[tf, idx] = ismember('EXPTIME', keywords(:,1));
if tf
exposure_time = keywords{idx,2};
else
tf = nan;
end
  1 Comment
Chris Anast
Chris Anast on 5 Feb 2018
At first, this was giving a 'Reference to non-existing field' error. However that is because the second line should have been:
keywords = info.Image.Keywords;
for my case. Thank you very much, sir!
Regards, Kristian

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!