BAI=xlsread('Sim_16.xlsx','C7:V7');

BN=zeros(1,20);
CFO=zeros(1,20);
CFI=zeros(1,20);
credf=0;
tipoimp=0.3;
IMP=zeros(1,20);
for j=1:20
    if BAI(j)>=0
        if credf<(BAI(j)*tipoimp)
   IMP(j)=BAI(j)*tipoimp-credf;
   credf=0;
        elseif credf>(BAI(j)*tipoimp)
            IMP(j)=0;
            credf=credf-(BAI(j)*tipoimp); 
        end
    else
        IMP(j)=0;
        credf=credf+abs(tipoimp*BAI(j));
        
    end
end

for j=1:20
    BN(j)=BAI(j)-IMP(j);
end

for j=1:20
    CFO(j)=BN(j)+125000;
end

for j=1:20
    CFI(j)=CFO(j);
end

xlswrite('Sim_16.xlsx',IMP,1,'C8:V8');
xlswrite('Sim_16.xlsx',BN,1,'C9:V9');
xlswrite('Sim_16.xlsx',CFO,1,'C11:V11');
xlswrite('Sim_16.xlsx',CFI,1,'C13:V13');

disp('HECHO');