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 Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by