function rho_3 = rho3(x,direct)
% function rho_3 = rho3(x)
% Evaluation of the index rho3 defined by yamashita
m = 0;    % counter
% for i = 1:(length(x) - 1)
%     if (x{i}(1) == 'I')&(x{i}(2) == 'S')
%         if (x{i+1}(1) == 'D')&(x{i+1}(2) == 'D')|...
%                 (x{i+1}(1) == 'D')&(x{i+1}(2) == 'I')|...
%                 (x{i+1}(1) == 'S')&(x{i+1}(2) == 'D')|...
%                 (x{i+1}(1) == 'I')&(x{i+1}(2) == 'D')|...
%                 (x{i+1}(1) == 'D')&(x{i+1}(2) == 'S')
%             m = m + 1;
%         end
%     end
%     if (x{i}(1) == 'D')&(x{i}(2) == 'S')
%         if (x{i+1}(1) == 'D')&(x{i+1}(2) == 'I')|...
%                 (x{i+1}(1) == 'S')&(x{i+1}(2) == 'I')|...
%                 (x{i+1}(1) == 'I')&(x{i+1}(2) == 'D')|...
%                 (x{i+1}(1) == 'I')&(x{i+1}(2) == 'I')|...
%                 (x{i+1}(1) == 'I')&(x{i+1}(2) == 'S')
%             m = m + 1;
%         end
%     end
% end
m = 0; m1 = 0; m2 = 0;    % counters
DS = 0; IS = 0;           % tags
for i = 1:(length(x) - 1)
    if (x{i}(1) == 'I')&(x{i}(2) == 'S')
        if IS == 1      % the last was also IS
            m1 = m1 + 1;
        else
            IS = 1;     % switch the IS tag on
            DS = 0;     % switch the DS tag off
            m1 = 1;     % start counter
            m2 = 0;     % reset the other counter
        end
        if (x{i+1}(1) == 'D')&(x{i+1}(2) == 'D')|...
                (x{i+1}(1) == 'D')&(x{i+1}(2) == 'I')|...
                (x{i+1}(1) == 'S')&(x{i+1}(2) == 'D')|...
                (x{i+1}(1) == 'I')&(x{i+1}(2) == 'D')|...
                (x{i+1}(1) == 'D')&(x{i+1}(2) == 'S')
            m = m + m1;
        end
    elseif (x{i}(1) == 'D')&(x{i}(2) == 'S')
        if DS == 1      % the last was also DS
            m2 = m2 + 1;
        else
            DS = 1;     % switch the DS tag on
            IS = 0;     % switch the IS tag off
            m2 = 1;     % start counter
            m1 = 0;     % reset the other counter
        end
        if (x{i+1}(1) == 'D')&(x{i+1}(2) == 'I')|...
                (x{i+1}(1) == 'S')&(x{i+1}(2) == 'I')|...
                (x{i+1}(1) == 'I')&(x{i+1}(2) == 'D')|...
                (x{i+1}(1) == 'I')&(x{i+1}(2) == 'I')|...
                (x{i+1}(1) == 'I')&(x{i+1}(2) == 'S')
            m = m + m2;
        end
    else
        IS = 0;     % neither IS
        DS = 0;     % nor DS
        m1 = 0;     % reset counters
        m2 = 0;
    end
end
rho_3 = rho1(x) - m/length(x);
return
