We can determine the sizes of some of the variables you've defined in this code from what you've shown, but others we cannot. In particular, we know that A_B is a scalar (0.80, the same value as A_pv) but we don't know the sizes of R_B or DOD. R_B is the product of a variable we know is a scalar (Z_B) and a variable about which we know nothing (daily_load_wh.) My guess is that at least one of those variables is non-scalar.
Why is the size of the variables important? From the documentation page for the if keyword, "An expression is true when its result is nonempty and contains only nonzero elements (logical or real numeric). Otherwise, the expression is false."
So on this line of your code:
If R_B is a vector, B_Energy_t(i) must be greater than all the elements of R_B*A_B or the if statement's condition is not satisfied. The same holds for the following line of code, where B_Energy_t(i) must be less than all the elements of R_B*DOD:
If I had to speculate, I'd guess DOD is a scalar and R_B is a vector making R_B*A_B and R_B*DOD both vectors the same size as R_B.
You might need to index into R_B or you may need to call any around the expression so if is satisfied if the condition is satisfied for any of the elements in R_B, not all. Alternately the min and/or max functions may be able to help you avoid the if statements entirely.