MATLAB Answers

Multiplying vector members without repeating

1 view (last 30 days)
Hi I need to multiply values from one vector in all combinations. For example Lets say that vector A=[1 2 3 4]' I need to get these products 1*2 1*3 1*4 2*3 2*4 3*4
Thanks for help

Accepted Answer

Stephen Cobeldick
Stephen Cobeldick on 4 Jul 2018
Edited: Stephen Cobeldick on 4 Jul 2018
>> A = 1:4;
>> prod(nchoosek(A,2),2)
ans =
2
3
4
6
8
12

More Answers (0)

Community Treasure Hunt

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

Start Hunting!