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 Exchange에서 Simulink에 대해 자세히 알아보기

질문:

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