Getting an error message and don't know how to fix

1 次查看(过去 30 天)
I have code that looks like this
% The loop
for i=1:N-1
v=diff(z);
v(i+1) = v(i) + h*(((-g-k*(abs(v)).^p)*V)/m);
z(i+1) = z(i)+h*v(i+1);
end
the error message has come up like this in the command window
Error in particle (line 24)
v(i+1) = v(i) + h*(((-g-k*(abs(v)).^p)*V)/m);
No idea what ive done, its probably a really easy fix but im having a blonde moment. New to this stuff. Thanks :)
  2 个评论
Holly Martin
Holly Martin 2019-11-21
Unable to perform assignment because the left and right sides have a different number of elements.
Error in particle (line 24)
v(i+1) = v(i) + h*(((-g-k*(abs(v)).^p)*V)/m);
Sorry- im so stupid sometimes haha

请先登录,再进行评论。

采纳的回答

the cyclist
the cyclist 2019-11-21
编辑:the cyclist 2019-11-21
abs(v)
is a vector, so the right-hand side is a vector. You are trying to put that into one element of v on the left-hand side.
Maybe you meant
abs(v(i))
there?

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by