how to automatically calculate probalities of a long binary sequence ?
    7 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
hello ,
i have a matlab data (2678400 values (seconds)) , converted to a binary sequence of 744 values of 0s and 1s . i need to calculate 4 probabilities (markov chain 4 states ) Pr(11),Pr(10),Pr(01),Pr(00) is there a code that can do that ?
thanks
0 Kommentare
Antworten (1)
  TARUN
 am 10 Jun. 2025
        If you have a binary sequence (e.g., converted from a large dataset like 2,678,400 values down to 744 binary values), and you'd like to compute Markov chain transition probabilities—specifically Pr(00), Pr(01), Pr(10), and Pr(11)—you can use the following MATLAB script:
% Initialization 
count_00 = 0;
count_01 = 0;
count_10 = 0;
count_11 = 0;
% for loop to count the transitions
for i = 1:length(binary_seq) - 1
    current = binary_seq(i);
    next = binary_seq(i + 1);
    if current == 0 && next == 0
        count_00 = count_00 + 1;
    elseif current == 0 && next == 1
        count_01 = count_01 + 1;
    elseif current == 1 && next == 0
        count_10 = count_10 + 1;
    elseif current == 1 && next == 1
        count_11 = count_11 + 1;
    end
end
% count the total transitions
total_transitions = count_00 + count_01 + count_10 + count_11;
% Compute probabilities
Pr_00 = count_00 / total_transitions;
Pr_01 = count_01 / total_transitions;
Pr_10 = count_10 / total_transitions;
Pr_11 = count_11 / total_transitions;
% display the results
disp(['Pr(00) = ' num2str(Pr_00)]);
disp(['Pr(01) = ' num2str(Pr_01)]);
disp(['Pr(10) = ' num2str(Pr_10)]);
disp(['Pr(11) = ' num2str(Pr_11)]);
The above script helps you compute the first-order Markov transition probabilities by analysing every pair of consecutive bits in your binary sequence.
0 Kommentare
Siehe auch
Kategorien
				Mehr zu Markov Chain Models finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

