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

 Accepted Answer

Stephen23
Stephen23 on 25 Aug 2020
Edited: Stephen23 on 25 Aug 2020
X = X1+[0;cumsum(Vx(1:end-1).*diff(T))]
Y = Y1+[0;cumsum(Vy(1:end-1).*diff(T))]

1 Comment

Thank you very much for your solution.

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

on 25 Aug 2020

Edited:

on 25 Aug 2020

Community Treasure Hunt

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

Start Hunting!