MATLAB: How to read fits files from a directory

directoryfitsfitsreadMATLABstruct2char

Hello,
First of, sorry if this is a novice question. I have a bunch of FITS files in my folder that I have to average. I decided to create a directory of them and then read them in a for loop as follows but at the end I get f as just the last FITS. How do I make f be created and contain all the FITS from the directory so it can be read by r (if possible)?
d = dir('capture_*.fit');
for n = 1:length(d)
f = d(n).name;
end
r = fitsread(f);
Thanks in advance, Kres

Best Answer

I did it like this:
d = dir('capture_*.fit');
for j = 1:length(d);
s = d(j).name; %get name of image from directory
r = fitsread(s); %read the image
sum_image = sum_image + r; %sum images up one by one
end
avg_image = sum_image ./ number_images; %find the averaged image
imagesc(avg_image); %plots averaged image
But your answer game me the inspiration. Thanks.
Related Question