Subtract element one from element two in a 1x101 row vector.
2 ビュー (過去 30 日間)
古いコメントを表示
I need to subtract the first element of a vector from the second element. Then continue in that manner.
E3 - E2 then E4 - E3 then E5 - E6 to the end.
% Calculate the Velocity and Accelleration for particle 1 at all times.
load A1_input.txt;
t=A1_input(:,1)'; % Time in Seconds.
% Calculate the Time for particle using loops.
for i=1:length(t)
Time(i) =(t(:,2))-(t(:,1));
end
Time(36) % Trial ans wrong
0 件のコメント
回答 (1 件)
Mohammad Sami
2021 年 8 月 2 日
編集済み: Mohammad Sami
2021 年 8 月 2 日
You can use the subset from 1:end-1 and 2:end to calculate without using the for loop.
t = rand(1,101);
tsub = t(2:end) - t(1:end-1)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!