Combinations of different rows of a matrix
Show older comments
I have a 90x2 matrix. I have to generate all combinations of 2 rows of the matrix. How can I do it?
Plz help
Accepted Answer
More Answers (1)
Alex Mcaulley
on 19 Jun 2019
A = rand(90,2); %Example
b = nchoosek(1:size(A,1),2);
res = reshape(cell2mat(arrayfun(@(i) A(b(i,:),:),1:size(b,1),'uni',0)),2,size(A,2),[]);
4 Comments
Jess
on 19 Jun 2019
Alex Mcaulley
on 19 Jun 2019
If you execute the code as is it should work. Probably the problem is with your matrix
Jess
on 19 Jun 2019
Jess
on 20 Jun 2019
Categories
Find more on Linear Algebra in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!