generate_stimulus_sequence

for t = 1:stim_time

  tprev = max(1, t-1);

  Scs(t,:) = rand(1,numCS) < CS(t,:);
  Pcs(t,:) = (rand(1,numCS) < V(tprev,:)) .* Scs(t,:);
  Tcs(t,:) = max(Scs(t,:),(1-theta)*Tcs(tprev,:));
  Phics(t,:) = Tcs(t,:) .* (1-Tcs(t,:));

  if any(Pcs(t,:)==1) | Sfi(t)==1 | US(t) == 1
    Amn(t) = Amn(tprev) + delta1 * (1 - Amn(tprev));
  else
    Amn(t) = Amn(tprev) - delta2 * Amn(tprev);
  end

  V(t,:) = V(tprev,:) + ...
      (rand(1,2)<Phics(t,:)) .* beta1 .* (1-V(tprev,:)) * US(t) + ...
      Pcs(t,:) .* -beta2 .* V(tprev,:);

end

