function [Shear, Slope] = ShearStrengthAdj(Strain, Shear, Slope, ShearStrength)
%SHEARSTRENGTHADJ Summary of this function goes here
%   Detailed explanation goes here

Adj = 0;
ShearTrial = Shear(end);
i = 0;

if ShearTrial > ShearStrength
    
    % Check if Shear Stress is greater than Shear Strength
    while Shear(end-i) > ShearStrength
        Shear(end-i) = ShearStrength;
        i = i + 1;
    end
    
    % Check if last Shear Stress value is lower than Shear Strength
elseif ShearStrength > ShearTrial
    
    while ShearStrength > ShearTrial
        
        i = i + 1;
        
        if i == length(Shear)
            close
            errordlg('Max Shear Strength too high.')
            return
        end
        
        % Determine how many Shear Stress Values need to be updated
        ShearTrial = Shear(end-i) + (Strain(end) - Strain(end-i))*Slope(end-i);
        Adj = 1;
        
    end
    
    % Update last shear stress
    if ShearTrial > ShearStrength && Adj == 1
        Shear(end) = ShearStrength;
    elseif ShearTrial <= ShearStrength && Adj == 1
        Shear(end) = ShearTrial;
    end
    
    % Update shear stress
    for j = i-1:-1:1;
        Shear(end-j) = Shear(end-j-1) + (Strain(end-j) - Strain(end-j-1))*Slope(end-i);
        if Shear(end-j) > ShearStrength
            Shear(end-j) = ShearStrength;
        end
    end
    
end

% Update slope for where shear stress was updated
for j = 1:i
    Slope(end-j+1) = (Shear(end-j+1) - Shear(end-j))/(Strain(end-j+1) - Strain(end-j));
end


end

