Borrar filtros
Borrar filtros

how to get combination of elements in a matrix in pair order

2 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Stephan
Stephan el 11 de Jul. de 2019
Editada: Stephan el 11 de Jul. de 2019
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

Más respuestas (1)

Andrei Bobrov
Andrei Bobrov el 11 de Jul. de 2019
Editada: Andrei Bobrov el 11 de Jul. de 2019
A=[3 5 6 7 8];
[y,x] = ndgrid(A);
B = [x(:),y(:)];
B = B(diff(B,1,2) ~= 0,:);

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by