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)')

 채택된 답변

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일

0 개 추천

댓글 수: 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!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

질문:

2015년 11월 17일

댓글:

2015년 11월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by