Consider the following:
%
N = 11;
%
trans = rand(N,N);
trans = bsxfun(@rdivide, trans, sum(trans,2));
%
emis = ones(N,1);
%
[~,states] = hmmgenerate(10, trans, emis)
The sequence of generated states:
>> states
states =
10 1 3 11 9 4 11 1 4 6
EDIT:
In fact, working with the Markov chain is relatively simple, we can do it ourselves. Here is another example without using the HMM functions from the statistics toolbar.
%
N = 3;
%
trans = rand(N,N);
trans = bsxfun(@rdivide, trans, sum(trans,2));
%
prior = rand(1,N);
prior = prior ./ sum(prior);
%
len = 100; %
states = zeros(1,len);
states(1) = randsample(N, 1, true, prior);
for t=2:len
states(t) = randsample(N, 1, true, trans(states(t-1),:));
end
%
stairs(states, 'LineWidth',2)
set(gca, 'YGrid','on', 'YLim',[0 N+1])
xlabel('time'), ylabel('states')
title('sequence of states')

RANDSAMPLE . ( ), . MATLAB .