필터 지우기
필터 지우기

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