Error using plot, vectors must be of the same length

1 次查看(过去 30 天)
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)')

采纳的回答

Thorsten
Thorsten 2015-11-17
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 个评论
Sean10
Sean10 2015-11-17
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.

请先登录,再进行评论。

更多回答(1 个)

Image Analyst
Image Analyst 2015-11-17
  1 个评论
Sean10
Sean10 2015-11-17
Thanks for the heads up with the formatting. Also thanks for the video i'll check it out now!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by