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

1 回表示 (過去 30 日間)
function [t,v]= Partc ( m,c,g,t0,v0,tn,n )
fprintf('values of t approximations v(t)\n')
fprintf('%8.3f',t0)
fprintf('%19.4f\n',v0)
h=(tn-t0)/n;
t=[t0:h:tn];
v=zeros(1, n);
v(1)=v0;
for i=1:n
v(i+1)=v(i)+(g*m/c)*(1-exp(-c*t/m)));
fprintf('%8.3f',t(i+1));
fprintf('%19.4f\n',v(i+1));
end
plot(t,v)
end
Line 10: (( v(i+1)=v(i)+(g*m/c)*(1-exp(-c*t/m))); keeps giving me the "Unable to perform assignment because the left and right sides have a different number of elements" error. Any help would be appreciated.

回答 (1 件)

per isakson
per isakson 2019 年 1 月 21 日
編集済み: per isakson 2019 年 1 月 21 日
Maybe replace
v(i+1)=v(i)+(g*m/c)*(1-exp(-c*t/m)));
by
v(i+1)=v(i)+(g*m/c)*(1-exp(-c*t(i)/m)));
v(i+1) is a scalar, I assume, thus the rhs should be a scalar.
Does that make sense?

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by