MATLAB: How to plot a transient voltage response before and after a switch is thrown

MATLABplot

I currently have the following code:
% Define the time step
% x = [ start: step: stop]
t = [ - 10e-6 : 1e-8 : 150e-6];
% BEFORE SWITCH IS THROWN
Vc(t<0) = 4.604;
% AFTER SWITCH IS THROWN
Req = 6.334e3;
C = 2.7e-9;
tau = Req * C;
Vc(t>0) = 4.604 * (1 + exp(-t / tau));
plot(t, Vc);
title('Capacitor Voltage vs Time');
xlabel('Time (s)');
ylabel('Voltage (V)');
I need to plot the DC voltage before time is 0 as a flat line at 4.604V, then after as an exponential decay.
Have been trying for a while and can't seem to get it. Any tips would be very appreciated!

Best Answer

%if true
Vc(t>0) = 4.604 * (1 + exp(-t(t>0)./ tau));
plot(t, Vc);
title('Capacitor Voltage vs Time');
xlabel('Time (s)');
ylabel('Voltage (V)');