Array indices must be positive integers or logical values.

2 visualizaciones (últimos 30 días)
Murad Alzahrani
Murad Alzahrani el 16 de Jul. de 2019
Editada: the cyclist el 16 de Jul. de 2019
function [out] = slope(t,G1,G2,G3,G4)
k1=10;k2=20;m1=2;m2=4;
out(1)=(-k1*G2+k2(G4-G2))/m1;
out(2)=G1;
out(3)=-k2(G4-G2)/m2;
out(4)=G3;
end
when I use this function liks slope(0,1,0,-1,0)
show me thia Array indices must be positive integers or logical values.
Error in slope (line 4)
out(1)=(-k1*G2+k2(G4-G2))/m1;
why? how I can fix it.

Respuestas (1)

the cyclist
the cyclist el 16 de Jul. de 2019
Editada: the cyclist el 16 de Jul. de 2019
You need to explicitly put in the multiplication sign:
out(1)=(-k1*G2+k2*(G4-G2))/m1;
and similarly in the assignment to out(3):
out(3)=-k2*(G4-G2)/m2;

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by