Combinations of different rows of a matrix
    4 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Jess
 am 19 Jun. 2019
  
    
    
    
    
    Beantwortet: Stephen23
      
      
 am 20 Jun. 2019
            I have a 90x2 matrix. I have to generate all combinations of 2 rows of the matrix. How can I do it?
Plz help
0 Kommentare
Akzeptierte Antwort
  Stephen23
      
      
 am 20 Jun. 2019
        Simpler using basic MATLAB indexing:
>> M = [1,5;6,2;5,6;7,5;9,0]
M =
   1   5
   6   2
   5   6
   7   5
   9   0
>> X = nchoosek(1:size(M,1),2);
>> R = [M(X(:,1),:),M(X(:,2),:)]
R =
   1   5   6   2
   1   5   5   6
   1   5   7   5
   1   5   9   0
   6   2   5   6
   6   2   7   5
   6   2   9   0
   5   6   7   5
   5   6   9   0
   7   5   9   0
0 Kommentare
Weitere Antworten (1)
  Alex Mcaulley
      
 am 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 Kommentare
Siehe auch
Kategorien
				Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!