Product of elements in an array

3 ビュー (過去 30 日間)
Raghavasimhan Thirunarayanan
Raghavasimhan Thirunarayanan 2019 年 2 月 20 日
回答済み: Matt J 2019 年 2 月 20 日
I have an array as such (3 5 7 11), I want to find out the unique multiples of these elements i.e.
1) product of pairwise elements -- 15, 21, 33, 35, 55, 77
2) product of three elements -- 105, 385, 231
3) product of four elements -- 1055.
I am currently confused as to how to go about it in an efficient way so that when I extend it to larger number of elements in the array, I don't explode my memory and kill my computer. Any help would be greatly appreciated.
Thanks

回答 (1 件)

Matt J
Matt J 2019 年 2 月 20 日
For example,
>> x=[3 5 7 11];
>> prod(nchoosek(x,3),2)
ans =
105
165
231
385

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by