MATLAB: How do i get the graph to produce a straight line other than just points? Thanks.

graph plotting

for t=0:1:25
if t<5
v=(0.1553567*t^6)-(2.0416*t^5)+(9.1837*t^4)-(14.829*t^3)-(1.3704*t)+(32.821*t)-1.3155;
plot(t,v,'b+-')
hold on
end
if t>=5&&t<15.4
v=(0.003980879*t^5)-(0.2247*t^4)+(4.8682*t^3)-(50.442*t^2)+(254.67*t)-430.66;
plot(t,v,'b+-')
hold on
end
if t>=15.4
v=-(0.073*t^2)+(6.1802*t)+40.423;
plot(t,v,'b+-')
hold on
end
title('Camero Accelerating')
xlabel('Time(s)')
ylabel('Speed(mph)')
xlim([0 30])
ylim([0 160])
end

Best Answer

t=0:1:25;
v = zeros(1,numel(t)); %PRE-ALLOCATION
for i = 1:numel(t)
if t(i)<5;
v(i)=(0.1553567*t(i)^6)-(2.0416*t(i)^5)+(9.1837*t(i)^4)-(14.829*t(i)^3)-(1.3704*t(i))+(32.821*t(i))-1.3155;
elseif t(i)>=5&&t(i)<15.4;
v(i)=(0.003980879*t(i)^5)-(0.2247*t(i)^4)+(4.8682*t(i)^3)-(50.442*t(i)^2)+(254.67*t(i))-430.66;
else t(i)>=15.4;
v(i)=-(0.073*t(i)^2)+(6.1802*t(i))+40.423;
end
end
plot(t,v,'-+b')
title('Camero Accelerating')
xlabel('time(s)')
ylabel('Speed(mph)')
xlim([0 30])
ylim([0 160])