Is there a product function that works in the same way as diff?
6 ビュー (過去 30 日間)
古いコメントを表示
I know that the diff function gives you an array with the difference of the array elements. Is there a function that works in the same manner but instead of difference gives me the product of every other element?
0 件のコメント
採用された回答
Stephen23
2019 年 2 月 8 日
"...but instead of difference gives me the product of every other element?"
It is not clear what you mean by "every other element", but perhaps you mean either of these:
>> V = randi(9,1,8)
V =
8 4 6 2 9 7 6 9
>> V(1:end-1).*V(2:end) % product of adjacent elements
ans =
32 24 12 18 63 42 54
>> V(1:2:end).*V(2:2:end) % product of alternating elements
ans =
32 12 63 54
その他の回答 (1 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!