MATLAB: Error using plot, vectors must be of the same length

error using plotgraphplotvectorvectorsvectors must be of the same length

I know this basically means that the two outputs are of different vector lengths so cant be plotted against each other, however i am not sure how to fix this in my coding, shown below. Thanks in advance for any advice!
R=input('Enter the radius of the turn > '); chim=input('Enter the angle of the turn > '); vf=input('Enter the velocity of the vehicle > '); %tmax=input('Enter the total manoeuvre time > '); dt=input('Enter the time increment for the discretisation > ');
chidm=vf/R; k=0.15; t1=2*k*((chim)/(chidm)); t2=t1+(2*R*chim*(1-(2*k)))/(2*vf); tmax=360; a1=(-2*chidm)/(t1^3); b1=3*chidm/(t1^2); a3=(2*chidm)/(tmax-t2)^3; b3=(-3*(t2+tmax)*chidm)/(tmax-t2)^3; c3=(6*t2*tmax*chidm)/(tmax-t2)^3; d3=chidm-((chidm*(3*tmax-t2)*t2^2)/(tmax-t2)^3);
global t mpts t=0 : dt : tmax; mpts=length(t);
if t>=0 & t<=t1 chid=a1*t.^3+b1*t.^2; chi=(1/4)*a1*t.^4+(1/3)*b1*t.^3; elseif t1<t & t<t2 chid=chidm; chi=chidm*t; elseif t2<=t & t<=tmax chid=a3*t.^3+b3*t.^2+c3*t+d3; chi=((1/4)*a3*t.^4)+((1/3)*b3*t.^3)+((1/2)*c3*t.^2)+(d3*t); end
plot(t,chid),xlabel('t (s)'),ylabel('chid (deg/s)')

Best Answer

Use a loop to determine the chid and chi values for different t
tall = t;
for i=1:numel(tall)
t = tall(i);
if t>=0 & t<=t1
chid(i)=a1*t.^3+b1*t.^2;
chi(i)=(1/4)*a1*t.^4+(1/3)*b1*t.^3;
elseif t1<t & t<t2
chid(i)=chidm;
chi(i)=chidm*t;
elseif t2<=t & t<=tmax
chid(i)=a3*t.^3+b3*t.^2+c3*t+d3;
chi(i)=((1/4)*a3*t.^4)+((1/3)*b3*t.^3)+((1/2)*c3*t.^2)+(d3*t);
end
end