check each element of random vector c=[0, 1, 0, 1,.....n] one by one if value of current element is 0 and previous element is 0 perform this action otherwise another action.
2 views (last 30 days)
I want to run for loop to Check each element of random vector c=[0, 1, 0, 1,.....n] if value of 1st element is 0 and next element is 0 perform summation of certian values, if 1st element is 0 and next element is 1 then perform summation of certain values,if 1st element is 1 and next element is 0 then perform summation of certain values and if 1st element is 1 and next element is 1 then perform summation of certain values. This will continue till end so we need to check the element and the previous element.
function [Total_delay_upper, Total_delay_lower] = f_Cummulative_delay(c,T_pUU,T_pUL,T_pLL,T_pLU)
Total_delay_upper = T_pUU;
Total_delay_lower = T_pLL;
Total_delay_upper = T_pUL;
Total_delay_lower = T_pLU;
Total_delay_upper = Total_delay_upper+T_pUU;
Total_delay_lower = Total_delay_lower+T_pLL;
Total_delay_upper = Total_delay_upper+T_pUL;
Total_delay_lower = Total_delay_lower+T_pLU;
Upperdelay = Upperdelay(i)+T_pUL;
Lowerdelay = Lowerdelay(i)+T_pLU;
the cyclist on 8 Jun 2022
I didn't fully understand what you are trying to do with your code, but I think the following will help you.
To find all the locations of the pair [0 1] in a vector c, you can simply do
c = [0 1 0 1 1 0 1 0 1 0 1 1];
index01 = strfind(c,[0 1])
and you can do similarly for the other patterns:
index10 = strfind(c,[1 0])
index11 = strfind(c,[1 1])
You should then be able to use those indices to index into your other array that you want to sum.