Is there a product function that works in the same way as diff?

6 ビュー (過去 30 日間)
Arvind Balaji
Arvind Balaji 2019 年 2 月 8 日
コメント済み: Arvind Balaji 2019 年 2 月 8 日
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?

採用された回答

Stephen23
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 件のコメント
Arvind Balaji
Arvind Balaji 2019 年 2 月 8 日
Yes this is perfect. I wanted adjacent elements. Thanks!

サインインしてコメントする。

その他の回答 (1 件)

madhan ravi
madhan ravi 2019 年 2 月 8 日

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by