distanceIn=[];
distanceOut=[];
powerIn=[];
powerOut=[];
for x=1:203
    for y=1:203
        if Cell_Info_A.ReceivedPowerMap(y,x)~=0 & (x~=101 & y~=101)
            if BinaryMask(ChangeCoordsAy(y),ChangeCoordsAx(x))==0
                distanceOut(end+1)=10*sqrt((x-101)^2+(y-101)^2);
                powerOut(end+1)=Cell_Info_A.ReceivedPowerMap(y,x);
            else
                distanceIn(end+1)=10*sqrt((x-101)^2+(y-101)^2);
                powerIn(end+1)=Cell_Info_A.ReceivedPowerMap(y,x);
            end
        end
    end
end

for x=1:203
    for y=1:203
        if Cell_Info_C.ReceivedPowerMap(y,x)~=0 & (x~=101 & y~=101)
            if BinaryMask(ChangeCoordsCy(y),ChangeCoordsCx(x))==0
                distanceOut(end+1)=10*sqrt((x-101)^2+(y-101)^2);
                powerOut(end+1)=Cell_Info_C.ReceivedPowerMap(y,x);
            else
                distanceIn(end+1)=10*sqrt((x-101)^2+(y-101)^2);
                powerIn(end+1)=Cell_Info_C.ReceivedPowerMap(y,x);
            end
        end
    end
end

for x=1:203
    for y=1:203
        if Cell_Info_D.ReceivedPowerMap(y,x)~=0 & (x~=101 & y~=101)
            if BinaryMask(ChangeCoordsDy(y),ChangeCoordsDx(x))==0
                distanceOut(end+1)=10*sqrt((x-101)^2+(y-101)^2);
                powerOut(end+1)=Cell_Info_D.ReceivedPowerMap(y,x);
            else
                distanceIn(end+1)=10*sqrt((x-101)^2+(y-101)^2);
                powerIn(end+1)=Cell_Info_D.ReceivedPowerMap(y,x);
            end
        end
    end
end

for x=1:203
    for y=1:203
        if Cell_Info_D.ReceivedPowerMap(y,x)~=0 & (x~=101 & y~=101)
            if BinaryMask(ChangeCoordsDy(y),ChangeCoordsDx(x))==0
                distanceOut(end+1)=10*sqrt((x-101)^2+(y-101)^2);
                powerOut(end+1)=Cell_Info_D.ReceivedPowerMap(y,x);
            else
                distanceIn(end+1)=10*sqrt((x-101)^2+(y-101)^2);
                powerIn(end+1)=Cell_Info_D.ReceivedPowerMap(y,x);
            end
        end
    end
end

% delta=Cell_Info_B.erp-Cell_Info_A.erp;
% for x=1:203
%     for y=1:203
%         if Cell_Info_B.ReceivedPowerMap(y,x)~=0 & (x~=101 & y~=101)
%             if BinaryMask(ChangeCoordsBy(y),ChangeCoordsBx(x))==0
%                 distanceOut(end+1)=10*sqrt((x-101)^2+(y-101)^2);
%                 powerOut(end+1)=Cell_Info_B.ReceivedPowerMap(y,x)-delta;
%             else
%                 distanceIn(end+1)=10*sqrt((x-101)^2+(y-101)^2);
%                 powerIn(end+1)=Cell_Info_B.ReceivedPowerMap(y,x)-delta;
%             end
%         end
%     end
% end

logp1Out=polyfit(log10(distanceOut),-powerOut,1);
predOut=polyval(logp1Out,log10(distanceOut));
nOut=logp1Out(1)/10;

logp1In=polyfit(log10(distanceIn),-powerIn,1);
predIn=polyval(logp1In,log10(distanceIn));
nIn=logp1In(1)/10;

figure
semilogx(distanceOut,-powerOut,'r.')
hold on
semilogx(distanceOut,predOut,'r-')
semilogx(distanceIn,-powerIn,'b.')
semilogx(distanceIn,predIn,'b-')
title('Variation of received power and distance (assuming erp=25.0515)')
xlabel('Distance between transmitter and receiver (m)')
ylabel('Path loss (dBm)')
legend('Outdoor data','Outdoor regression','Indoor data','Indoor regression')