Hi ...how to generate transition probability matrix using markov property for acceleration and velocity ?
1 次查看(过去 30 天)
显示 更早的评论
I want to generate a transition probability matrix for acceleration and velocity ,but the problem is I don't have data for acceleration and velocity so I want to use rand command to generate a random values.I already found a code for acceleration and velocity data but in this code they have loaded a data and from that data they generate the TPM matrix .But in my case I want to use a rand command for accel and velocity in order build the TPM matrix .How can I do it?Thank you.
function transMat = mwExample
load('Sample data set mathworks.mat')
%%First bin data into categories
speedBinN = 5;
aceelBinN = 5;
speed = binit( data(:,2), linspace(min(data(:,2)),max(data(:,2)),speedBinN) ); % bin them into categories
accel = binit( data(:,3), linspace(min(data(:,3)),max(data(:,3)),aceelBinN) );
%%count up transitions
transCountMat = zeros(speedBinN,aceelBinN,speedBinN,aceelBinN);
for ii = 1:size(data,1)-1
transCountMat( speed(ii),accel(ii),speed(ii+1),accel(ii+1) ) = transCountMat( speed(ii),accel(ii),speed(ii+1),accel(ii+1) ) + 1;
end
%%calculate probabilities
sumOverPossibleDestinations = sum( sum(transCountMat, 4), 3);
transMat = bsxfun( @rdivide, transCountMat, sumOverPossibleDestinations )
0 个评论
回答(1 个)
Sarah Mohamed
2018-1-3
Assuming 'data' contains the speed and acceleration loaded from the sample file, you can build a matrix of uniformly distributed random numbers using the 'rand' function.
It looks like 'data' is just a 2D matrix. If column 2 of 'data' contains the speed and column 3 contains the acceleration, you could create a random 2D matrix with three columns via:
data = rand(100, 3);
For more on this function, you may refer to the documentation link below:
2 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!