Clear Filters
Clear Filters

HI.Can someone please help me to create a transition probability matrix for the given data using markov chain?

1 view (last 30 days)
I have data for time,acceleration,speed.I'm attaching the data file above.I'm trying to generate a 2 dimensional transition probability matrix of velocity and acceleration but with different state of velocity and acceleration. The idea is generate a particular speed and acceleration I would like to know the next most probable speed and acceleration.I tried to use a code ,my i could not succeed if someone help me on this it will be a great help.Thank you.
binN='bindata.mat';
%%First bin data into categories
speedBinN = 5;
aceelBinN = 5;
speed = histc( binN(:,2), linspace(min(binN(:,2)),max(binN(:,2)),speedBinN) ); % bin them into categories
accel = histc( binN(:,3), linspace(min(binN(:,3)),max(binN(:,3)),aceelBinN) );
%%count up transitions
transCountMat = zeros(speedBinN,aceelBinN,speedBinN,aceelBinN);
for n = 1:size(binN,1)-1
transCountMat( speed(n),accel(n),speed(n+1),accel(n+1) ) = transCountMat( speed(n),accel(n),speed(n+1),accel(n+1) ) + 1;
end
%%calculate probabilities
%trans = full(sparse(bins(1:end-1), bins(2:end), 1));
%trans = bsxfun(@rdivide, trans, sum(trans,2));
sumOver = sum( sum(transCountMat, 4), 3);
transMat = bsxfun( @rdivide, transCountMat, sum(sumOver,2) )

Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!