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 个)

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 Exchange 中查找有关 Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by