Indexing cannot yield multiple results error
Afficher commentaires plus anciens
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?
Réponses (1)
Mischa Kim
le 15 Oct 2014
Modifié(e) : Mischa Kim
le 15 Oct 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;
Catégories
En savoir plus sur Simulink dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!