function [Y_new] = new_state(A_ij,Y_old) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% function [Y_new] = new_state(A_ij,Y_old) %% %% %% %% DESCRIPTION: %% %% compute the new state given the previous one %% %% and the transition matrix %% %% PARAMETERS: %% %% A_ij = transition matrix %% %% Y_old = previous state %% %% Y_new = new state %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Y_new = 0; count=0; N_state=size(A_ij,1); P=A_ij(:,Y_old)'; P1=cumsum(P); P2=zeros(1,N_state+1); P2(2:N_state+1)=P1; x = rand(1); %fprintf('x = %f\n',x); for i=2:N_state+1, if (x>=P2(i-1))&(x1), fprintf('Error - The new state has not found properly\n'); end;