Every time I run this code, I get "Error using plot Vectors must be the same length. Error in ex (line 22)

1 次查看(过去 30 天)
%prameters
L = 160
w = 1000 * 2 * pi/60
r = 60
N = 100
th0 = 0
thl = 180
dth = (thl - th0)/N
q=r/L
%calculation
for i = 0:1:N;
th = (th0 + i * dth) * pi/180;
phi = asin (q * sin(th));
dphidt = w * q * cos(th)/sqrt(1 - (q * sin(th))^2);
vd (i + l) = w * r * sin(phi + th)/cos(phi);
wbd(i + l) = -w * r * cos(th)/(L * cos(phi));
ad(i + l)= w * r * ((cos(phi) * cos(phi + th) * (w + dphidt) - sin(phi) * sin(phi + th) * dphidt)/cos(phi)^2);
albd (i + l) = -w * q * ((-cos(phi) * sin(th) * w + sin(phi) * cos(th) *dphidt)/cos(phi)^2);
end
figure
plot ((th0:dth:thl) , wbd , (th0:dth:thl) , albd/100 ,'lineWidth', 2);
xlabel ('\theta ({\circ})') ;
legend ('\omega_{BD} (rad/s)','\alpha_{BD} (10^2 rad/s^2');
axis ([th0 thl - inf inf]);
figure
plot ( [th0:dth:thl] , vd/10 , [th0:dth:thl] , ad/1000 , 'LineWidth' , 2 );
xlabel ('\theta ({\circ})');
legend ('v_D (10^1 in/s)','a_D (10^3 in/s^2)');
axis ([tho thl - inf inf]);
N = 100
thl = 180
N = 100
clc

回答(1 个)

Kumar Pallav
Kumar Pallav 2021-11-24
Hi,
I assume the variable "L" defined in parameters has to be used instead of "l" inside the for loop.
The error you are getting at this line:
plot ((th0:dth:thl) , wbd , (th0:dth:thl) , albd/100 ,'lineWidth', 2);
Now, the error you are getting is because the plot takes two vectors:
a. (th0:dth:thl) of dimension 1*101 double
b. wbd of dimension 1*260 double
You must have same size of vectors to plot. Refer this for more on plot function.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by