function [Strain, Shear, Slope, SlopeRatio] = NYSAdj(Strain, Shear, Slope, SlopeRatio, NYS)

while NYS > length(Strain)
    
    Slope = zeros(1, length(Shear));
    Slope(1) = Shear(1)/Strain(1);
    for i = 1:length(Shear)-1
        Slope(end-i+1) = (Shear(end-i+1) - Shear(end-i))/(Strain(end-i+1) - Strain(end-i));
    end
    
    if Slope(end) ~= 0
        Slope(end+1) = 0;
    end
    
    StrainRange = Strain(2:end-1)-Strain(1:end-2);
    SlopeRatio = Slope(2:end-1)./Slope(1:end-2);
    
    if max(StrainRange) >= max(Strain(1:end-1))/length(Strain(1:end-1))
        ind = max(find(StrainRange == max(StrainRange)));
    else
        ind = min(find(SlopeRatio == min(SlopeRatio)));
    end
    
    if ind >= length(Slope)- 2 && Slope(ind+2) == 0
        m1 = Slope(ind)*2/3;
        m2 = Slope(ind)/3;
        NewStrain = (m1*Strain(ind)-m2*Strain(ind+1)-Shear(ind)+Shear(ind+1))/(m1-m2);
        NewShear = m1*(NewStrain-Strain(ind))+Shear(ind);
    else
        R = (1 - Slope(ind+2)/Slope(ind))/3;
        m1 = Slope(ind)*(1-R);
        m2 = Slope(ind)*(1-R*2);
        NewStrain = (m1*Strain(ind)-m2*Strain(ind+1)-Shear(ind)+Shear(ind+1))/(m1-m2);
        NewShear = m1*(NewStrain-Strain(ind))+Shear(ind);
    end
    
    if NewStrain >= Strain(ind+1) || NewStrain <= Strain(ind) || isnan(NewStrain)
        NewStrain = (Strain(ind+1)+Strain(ind))/2;
        NewShear = (Shear(ind+1)+Shear(ind))/2;
    end
    
    StrainTEMP = zeros(1,length(Strain)+1);
    ShearTEMP = zeros(1,length(Strain)+1);
    
    StrainTEMP = [Strain(1:ind) NewStrain Strain(ind+1:end)];
    ShearTEMP = [Shear(1:ind) NewShear Shear(ind+1:end)];
    
    Strain = StrainTEMP;
    Shear = ShearTEMP;
    
end

for i = 1:length(Shear)-1
    Slope(end-i+1) = (Shear(end-i+1) - Shear(end-i))/(Strain(end-i+1) - Strain(end-i));
end

SlopeRatio = Slope(2:end)./Slope(1:end-1);
