n_m1[dias,m] counts the number of transitions m -> 1 in the 22 years for each i
n_m0 <- matrix(0, (dias - K), 2^K) # matrix counting m -> 0
n_m1 <- matrix(0, (dias - K), 2^K) # matrix counting m -> 1
for(i in 1:(dias-K)){
for(j in 1:anos){
if(ozonio_sw[i+K,j] == 0){
for(n in 0:(2^K-1)){
if(mbase[i,j] == n){
count_Km[n+1,1] = count_Km[n+1,1]+1}}}
if(ozonio_sw[i+K,j] == 1){
for(n in 0:(2^K-1)){if(mbase[i,j] == n){
count_Km[n+1,2] = count_Km[n+1,2]+1}}} }
for(m in 1:(2^K)){
n_m0[i,m] = count_Km[m,1]
n_m1[i,m] = count_Km[m,2] }
count_Km <- matrix(0, 2^K, 2)
} # closes de i loop