Is it possible to vectorise this loop? Any help would be greatly appreciated.
% Calculate X(k)
for k = 1:length(T)
X(k) = (sum(Vx(1:k-1).*diff(T(1:k))))+ X1;
end
% Calculate Y(k)
for k = 1:length(T)
Y(k) = (sum(Vy(1:k-1).*diff(T(1:k))))+ Y1;
end

 Respuesta aceptada

Stephen23
Stephen23 el 25 de Ag. de 2020
Editada: Stephen23 el 25 de Ag. de 2020

0 votos

X = X1+[0;cumsum(Vx(1:end-1).*diff(T))]
Y = Y1+[0;cumsum(Vy(1:end-1).*diff(T))]

1 comentario

Michael Ng
Michael Ng el 25 de Ag. de 2020
Thank you very much for your solution.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de Ag. de 2020

Editada:

el 25 de Ag. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by