I'm not sure what the difference between x_a and x_a,m is, but maybe this would work:
x = [1, 1, 1, 1, 1, 0];
m = 4;
t = 6;
sum_x = sum(x(max(0,t-m+1):t));
if sum_x == m && x(t-1) == 0
x(t) = 1;
elseif sum_x == m && x(t-1) == 1
x(t) = 0;
else
x(t) = x(t-1);
end
disp(x(t))
this assumes that x_a and x_a,m are the same list