Indexing cannot yield multiple results error

I have made a function where I call on other functions.
My mother-function coding looks like this:
-------------------------------------------------------------
function [yvektor, xvektor] = trajectory(angle,speed,h)
dt = 0.01;
[vx, vy] = initialSpeed(angle, speed);
x0 = 0;
y0 = h;
i = 1;
y = h;
while y > 0
[ax, ay] = acceleration(vx, vy);
[vx, vy] = speed(vx, vy, ax, ay, dt);
[x, y] = position(x0, y0, vx, vy, dt);
yvektor(i) = y
xvektor(i) = x
i = i + 1;
end
end
---------------------------------------
And my speed function looks like this:
----------------------------------------------
function [vx, vy] = speed(vx, vy, ax, ay, dt)
vx = vx + ax*dt vy = vy + ay*dt
end
-----------------------------------------------------
When i try to run the trajectory function, the error :
''Indexing cannot yield multiple results.
Error in trajectory (line 11) [vx, vy] = speed(vx, vy, ax, ay, dt);'' appears.
Any idea on what I've done wrong. I've been looking for mistypes for half an hour, but I'm starting to think this error is something deeper.
Can anyone help me, please?

回答 (1 件)

Mischa Kim
Mischa Kim 2014 年 10 月 15 日
編集済み: Mischa Kim 2014 年 10 月 15 日

0 投票

Ole, the problem is in this statement
vx = vx + ax*dt vy = vy + ay*dt
These should be two separate statements. Change it to
vx = vx + ax*dt;
vy = vy + ay*dt;

カテゴリ

ヘルプ センター および File ExchangeSimulink についてさらに検索

質問済み:

2014 年 10 月 15 日

編集済み:

2014 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by