MATLAB Answers

0

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

Asked by SANJOY MONDAL on 11 Jul 2019
Latest activity Commented on by SANJOY MONDAL on 11 Jul 2019
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

  0 Comments

Sign in to comment.

2 Answers

Answer by Stephan
on 11 Jul 2019
Edited by Stephan
on 11 Jul 2019
 Accepted 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

  1 Comment

Sign in to comment.


Answer by Andrei Bobrov
on 11 Jul 2019
Edited by Andrei Bobrov
on 11 Jul 2019

A=[3 5 6 7 8];
[y,x] = ndgrid(A);
B = [x(:),y(:)];
B = B(diff(B,1,2) ~= 0,:);

  0 Comments

Sign in to comment.