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?

Respuestas (1)

Mischa Kim
Mischa Kim el 15 de Oct. de 2014
Editada: Mischa Kim el 15 de Oct. de 2014
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;

Categorías

Más información sobre Simulink en Centro de ayuda y File Exchange.

Preguntada:

el 15 de Oct. de 2014

Editada:

el 15 de Oct. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by