% This program simulates the hidden states of an HMM model % given the following input: % mu = Initial distribution (vector) % A = Transition probabilities between the hidden states (matrix) % n = Number of steps in the chain, minus one function [Pi] = hmmsim(mu,A,n) Pi = zeros(1,n); % place to store the states Pi(1) = rando(mu); % initial state has distribution mu for i = 1:n-1, Pi(i+1)=rando(A(Pi(i),:)); end;