clear all
clc

trans = [0.2 0.2 0.1 0.5;
        0.1 0.3 0.4 0.2;
        0.3 0.2 0.3 0.2;
        0.1 0.3 0.1 0.5];
    

 n=25;
 state = zeros(4,n);
 state(:,1) = 0.25*ones;
 
 path = zeros(n);
 
for i=1:5;
    for j=1:n;
        x = rand;
        position = find(x<cumsum(state(:,j)));
        path(j,i) = min(position);
        state(:,j+1)=trans(path(j,i),:)';
    end;
end; 

    figure(i)
    hold on;
    stairs(path(:,i));
    xlabel('time')
    ylabel('X(i) state')
    title(['Sample path' int2str(i)]);
    saveas(figure(i),['Sample path ' int2str(i) '.png'])
end;

    figure(6)
    hold on;
    stairs(path(:,1),':');
    stairs(path(:,2),'-');
    stairs(path(:,3),'--');
    stairs(path(:,4),'-.');
    stairs(path(:,5),'--.');
    xlabel('time')
    ylabel('X(i) state')
    title(['Sample path #1-5']);
    saveas(figure(6),['Sample paths 1-5.png'])
    