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 ExchangeLoops 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