MATLAB: How to get combination of elements in a matrix in pair order

matrix manipulationmatrix rearrange

I have a matrix A=[3 5 6 7 8]
i want the output in the form B= [ 3 5
3 6
3 7
3 8
5 3
5 6
5 7
5 8…] like this

Best Answer

A=[3 5 6 7 8];
b = nchoosek(A,2)
b =
3 5
3 6
3 7
3 8
5 6
5 7
5 8
6 7
6 8
7 8