So to start with you need to transform you data
matrix to a binned data matrix, B
(or basically just bin all the data). You can do it like this:
bins = -100:10:100;
B = arrayfun(@(x)find(x<=bins,1,'first')-1,data);
Now you need to count the transistions and create a grid. You can do this simply by going T = accumarray(B,1)
but for understanding here is is as a for loop:
n = numel(bins)-1;
T = zeros(n);
for k = 1:size(B,1)
T(B(k,1),B(k,2)) = T(B(k,1),B(k,2)) + 1;
end
and then to convert from this sort of joint histogram to a probability matrix
T = T/sum(T(:))
example:
a = rand(10,2)
a =
0.0534 0.1632
0.8664 0.4751
0.3270 0.6687
0.2016 0.4313
0.8158 0.6065
0.8493 0.4217
0.3997 0.3960
0.5845 0.1684
0.5499 0.3672
0.5886 0.4045
and
bins = 0:0.2:1;
do the calc:
B = arrayfun(@(x)find(x<=bins,1,'first')-1,data);
T = accumarray(B,1,[numel(bins)-1, numel(bins)-1])/size(B,1);
T =
0.1000 0 0 0 0
0 0.1000 0.1000 0.1000 0
0.1000 0.1000 0.1000 0 0
0 0 0 0 0
0 0 0.2000 0.1000 0
which is correct. You can see that 20% of the data transition from bin 5 to bin 3 for example and that corresponds to rows 2 and 6 from my a
matrix above.