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

 채택된 답변

Stephen23
Stephen23 2020년 8월 25일
편집: Stephen23 2020년 8월 25일

0 개 추천

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

댓글 수: 1

Michael Ng
Michael Ng 2020년 8월 25일
Thank you very much for your solution.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

질문:

2020년 8월 25일

편집:

2020년 8월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by