cant workout why vectors aren't the same length

1 次查看(过去 30 天)
kwr = zeros(length(0:0.001:0.01));
z = 0;
for X = 0:0.001:0.1;
z=z+1;
kwr(z)= ((ksr*((-4)*B*(X.^2) - 0.7*A*X+Rro).^2 - (Sr*dRrdX))./((-4)*B*(X.^2) - 0.7*A*X+Rro));
end
plot(X,kwr)
xlabel('verticle wheel travel (m)')
ylabel('wheel rate (N/m)')
title('verticle Wheel travel against rear wheel rate')
trying to plot this but keeps saying that the vectors are diferent sizes, cant see why

回答(1 个)

James Tursa
James Tursa 2019-5-15
编辑:James Tursa 2019-5-15
If you pass zeros( ) only one argument, it creates a square 2D matrix, not a vector. So give it two arguments to make your result a row vector:
kwr = zeros(1,length(0:0.001:0.01));
And you should set X
X = 0:0.001:0.1;
That being said, why not just avoid the loop entirely:
X = 0:0.001:0.1;
kwr = ((ksr*((-4)*B*(X.^2) - 0.7*A*X+Rro).^2 - (Sr*dRrdX))./((-4)*B*(X.^2) - 0.7*A*X+Rro));

类别

Help CenterFile Exchange 中查找有关 Two y-axis 的更多信息

产品


版本

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by