function S_AP0_DV0 = Poisson_OptimizeCoords(APcoords,DVcoords,Expression) %Data,TargetGene)

S_AP0_DV0 = [0 0 0];
Score = -1;
for S=0:0.025:1.5
    S
    for AP0 = 0:0.025:1
        for DV0 = 0:0.025:1
            % Rescale AP coordinates
            APnew = Poisson_Recoordinate(APcoords,DVcoords,S,AP0,DV0);
            
            % Compute mean intensity in each 1% of embryo length
            Z = NaN*zeros(99,1);
            for i=1:99
                I = find(round(APnew)==i);
                Z(i) = mean(Expression(I));
            end
            
            % Compute variance across bins
            I = find(isfinite(Z));
            TempScore = var(Z(I));
            
            if TempScore > Score
                Score = TempScore;
                S_AP0_DV0 = [S AP0 DV0];
            end
        end
    end
end





