Saving an array to a fits file

I have an array called frames_out. It's a 100x100x3000 array of images (3000 images, each image 100x100 pixels). I want to save this array as a FITS file. I've tried using the fitswrite function:
%%%%%%%%%
A = frames_out(:,:,1);
fitswrite(A,'fitsfile.fits')
for i = 2:size(frames_out,3)
A = frames_out(:,:,i);
fitswrite(A,'fitsfile.fits','writemode','append');
end
%%%%%%%%
But when I use the "fitsread" function on the FITS file I've created, that gives me an array with just one frame (the first frame of the original array), and I want all the images to be there. The weird thing is that if I use the code on just one frame, like this:
%%%%%%%%%
A = frames_out(:,:,1);
fitswrite(A,'fitsfile.fits')
%%%%%%%%
I get a FITS file whose size is a few hundred KB, and with the first code I get a much bigger file. So there's more information on the file from all the frames, but I can't seem to "extract" or see it anywhere.
Thanks a lot for your help,
Yael.

1 Comment

Did you ever find a way around this issue? I am having the same problem, and can't find anything online. I'm running Matlab R2015a. Thanks!

Sign in to comment.

Answers (1)

Reading the ith image: (adapted from the Mathwork's help for fitsread)
info = fitsinfo('fitsfile.fits');
rowend = info.Image.Size(1);
colend = info.Image.Size(2);
frames_in(:,:,i) = fitsread('fitsfile.fits','image',...
'Info', info,...
'PixelRegion',{[1 rowend], [1 colend], i });

1 Comment

yael
yael on 21 Nov 2014
Edited: yael on 21 Nov 2014
First of all, Thank you very much for your help. But using this code, I get an error:
"The given 'PixelRegion' value specifies 3 dimensions, but the data has 2 dimensions."
As though it still won't acknowledge the fact that there are multiple frames in fitsfile.

Sign in to comment.

Tags

Asked:

on 20 Nov 2014

Edited:

on 16 Apr 2016

Community Treasure Hunt

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

Start Hunting!