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

 Risposta accettata

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

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by