Unable to perform assignment because the left and right sides have a different number of elements.

2 次查看(过去 30 天)
I want to make a function tha carculates de speed of a train that accelerates uniformly en every point of the train having acceleration(a), train length (Lt) and start speed (v0) as inputs and i don t know why this error appears.
Does anyone know how to solve this?
Thanks
ERROR:Unable to perform assignment because the left and right sides have a different number of elements.
Error in VelTren (line 9)
v(i)=((v0.^2)+2*a*l).^(1/2);
function [v] = VelTren(v0,a,Lt)
l=0:0.1:Lt;
v=zeros(1,length(l));
v(1)=v0;
for i=2:length(l)
v(i)=((v0.^2)+2*a*l).^(1/2);
end
end

采纳的回答

Kevin Holly
Kevin Holly 2023-2-22
VelTren(1,9.81,46)
ans = 1×461
1.0000 1.7210 2.2190 2.6241 2.9746 3.2879 3.5738 3.8385 4.0861 4.3195 4.5409 4.7521 4.9542 5.1484 5.3355 5.5163 5.6914 5.8612 6.0263 6.1869 6.3435 6.4963 6.6456 6.7916 6.9346 7.0746 7.2119 7.3467 7.4790 7.6091
You need to change l to l(i).
function [v] = VelTren(v0,a,Lt)
l=0:0.1:Lt;
v=zeros(1,length(l));
v(1)=v0;
for i=2:length(l)
v(i)=((v0.^2)+2*a*l(i)).^(1/2);
end
end

更多回答(0 个)

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by