Here is a made-up example:
%# some random vector (load your data here instead)
x = randn(1000,1);
%# discretization/quantization into 8 levels
edges = linspace(min(x),max(x),8+1);
[counts,bins] = histc(x, edges);
%# fix last level of histc output
last = numel(counts);
bins(bins==last) = last - 1;
counts(last-1) = counts(last-1) + counts(last);
counts(last) = [];
%# show histogram
bar(edges(1:end-1), counts, 'histc')
%# transition matrix
trans = full(sparse(bins(1:end-1), bins(2:end), 1));
trans = bsxfun(@rdivide, trans, sum(trans,2));
A few things to note:
Discretization is performed simply by dividing the whole range of data into 8 bins. This is done using
histc
. Note that due to the way the function works, we had to combine the last two counts and fix the bins accordingly.the transition matrix is computed by first counting the co-occurrences using a less-known call form of the
sparse
function. Theaccumarray
could have also been used. The count matrix is then normalized to obtain probabilities that sum to one.You mentioned that your MC model should only allow transitions between adjacent states (1 to 2 or 8 to 7, but not between 2 and 5). I did not enforce this fact since this should be a property of the data itself, which is not applicable in this example with random data.