From a given vector create all combinations possible
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Tiago Dias
      
 el 26 de Jul. de 2019
  
    
    
    
    
    Comentada: Tiago Dias
      
 el 26 de Jul. de 2019
            Hello,
from a given vector i want to create all possible combinations.
I have the following code, a vector of [5 10 15] and I want to create the combinations of maxHiddenLayers numbers, it it has the value 2 i would get for example: 
[5 5; 5 10; 5 15; 10 5; 10 10; 10 15; 15 5; 15 10; 15 15]
With the code i got i am not geting the [5 5; 10 10; 15 15], i can't have the same number in the columns and i wanted.
maxHiddenLayers = 2;
minNeurons = 5;
maxNeurons = 15;
rangeNeurons = minNeurons:5:maxNeurons;
nk = nchoosek(rangeNeurons,maxHiddenLayers)
p = zeros(0,maxHiddenLayers);
for i=1:size(nk,1),
    pi = perms(nk(i,:));
    p = unique([p; pi],'rows')
end
0 comentarios
Respuesta aceptada
  Stephen23
      
      
 el 26 de Jul. de 2019
        
      Editada: Stephen23
      
      
 el 26 de Jul. de 2019
  
      >> V = [5,10,15];
>> [X,Y] = ndgrid(V);
>> M = [Y(:),X(:)]
M =
    5    5
    5   10
    5   15
   10    5
   10   10
   10   15
   15    5
   15   10
   15   15
4 comentarios
  Walter Roberson
      
      
 el 26 de Jul. de 2019
				[combo_cell{1:maxHiddenLayers}] = ndgrid(V);
temp_cell = cellfun(@(M) M(:), combo_cell, 'uniform', 0);
M = horzcat(temp_cell{:});
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


