If it throws an error, please include that information.
If that error is what I'm seeing:
Error using plot. Vectors must be the same length.
then the issue is that you're conditions don't include an x-value when t=4 (or -2,2, but these will be filled in with zeros). You can use <=, >=, or you don't want those points plotted, insert NaNs:
t = -4:0.1:4;
for k1 =1:length(t)
if (t(k1)>-4) && (t(k1)<-2)
x(k1) = (t(k1).^2) - (2.*t(k1))+3;
elseif (t(k1)>-2) && (t(k1)<2)
x(k1) = 4*cos(t(k1)*(2*pi*t(k1) - pi./8)) + 3*sin(2*pi*t(k1));
elseif (t(k1)>2) && (t(k1)<4)
x(k1) = sin(t(k1))./t(k1);
x(k1) = nan;