Error using plot, vectors 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)')

 Respuesta aceptada

Thorsten
Thorsten el 17 de Nov. de 2015
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

1 comentario

Sean10
Sean10 el 17 de Nov. de 2015
Yes that makes sense thanks for the reply! It still isnt quite producing the expected result i think i have to re-calculate my values for t1,t2 and tmax. But that solves the plotting issue! Thanks again.

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 17 de Nov. de 2015

1 comentario

Sean10
Sean10 el 17 de Nov. de 2015
Thanks for the heads up with the formatting. Also thanks for the video i'll check it out now!

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Preguntada:

el 17 de Nov. de 2015

Comentada:

el 17 de Nov. de 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by