clear all 
A=dir ('*filtered*.txt');
[s p]=size(load(A(1).name));
m=zeros(s,p,size(A,1));
for n=1:size(A,1)
   m(:,:,n)=load(A(n).name);
end
m_avg=zeros(s,p);
for n=1:s
    for l=1:p
        if sum(isnan(m(n,l,:)))==0
           m_avg(n,l)= mean(m(n,l,:));
        else 
            f=isnan(m(n,l,:));
            b=0;
            cnt=0;
            for u=1: size(A,1)
                if f(:,:,u)==0
                    b=m(n,l,u)+b;
                    cnt=cnt+1;
                end
                m_avg(n,l)=b/cnt;
            end    
        end
    end
end
m_avg=m_avg';
m_avg=horzcat([0:p-1]',m_avg);

m_avg(2:end,2:end)=m_avg(2:end,2:end)*1000;

csvwrite('dA_CHCl3_50mM_100um_260nm_300nJ',m_avg)

        

