Info
この質問は閉じられています。 編集または回答するには再度開いてください。
How do I do calculations with the last and first array member in a for loop?
1 回表示 (過去 30 日間)
古いコメントを表示
for example, I want to show another matrix that its elements are the sum of consecutive members in the original array, and the last showing the sum of the last with the first element, without explicitly managing the last case.
test = [1 2 3];
consecutiveSum = [ test(1) + test(2) , test(2) + test(3) , test(3) + test(1) ];
How can I implement this in a for loop?
0 件のコメント
回答 (1 件)
the cyclist
2018 年 9 月 5 日
編集済み: the cyclist
2018 年 9 月 5 日
test = [1 2 3];
N = numel(test);
idx = [1:N; [2:N,1]];
consecutiveSum = sum(test(idx));
0 件のコメント
この質問は閉じられています。
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!