wolffd@0: function S = mc_sample(prior, trans, len, numex) wolffd@0: % SAMPLE_MC Generate random sequences from a Markov chain. wolffd@0: % STATE = SAMPLE_MC(PRIOR, TRANS, LEN) generates a sequence of length LEN. wolffd@0: % wolffd@0: % STATE = SAMPLE_MC(PRIOR, TRANS, LEN, N) generates N rows each of length LEN. wolffd@0: wolffd@0: if nargin==3 wolffd@0: numex = 1; wolffd@0: end wolffd@0: wolffd@0: S = zeros(numex,len); wolffd@0: for i=1:numex wolffd@0: S(i, 1) = sample_discrete(prior); wolffd@0: for t=2:len wolffd@0: S(i, t) = sample_discrete(trans(S(i,t-1),:)); wolffd@0: end wolffd@0: end