Borrar filtros
Borrar filtros

create a matrix of combinations

1 visualización (últimos 30 días)
Colby
Colby el 20 de Jul. de 2016
Hello,
I'm trying to create a matrix with all possible combinations of combinations I guess.
If I run the follow code
n = 2 ; % number of canidates
sp = 4;% number of periods
M = dec2bin(0:(2^n)-1)-'0';
A = [1:sp];
for i = 2:size(M,1)
A = [A, 1:sp];
end
A = sort(A');
cnt = 1;
cnt2 = 0;
B = [M;M];
while size(B,1) < size(A,1)
B = [B;M];
end
C = [A,B];
I get the matrix C, with all possible combinations of candidates (columns 2 and 3), for every period (column 1). Now I would like to get a matrix that has all possible combinations of selecting one combination form each period.
So possible combinations would be 1 0 0, 2 0 0, 3 0 0, 4 0 0, or 1 0 1, 2 0 0, 3 0 0, 4 0 0, or 1 0 0, 2 0 1, 3 0 0, 4 0 0 and so on. Each combination must go 1xx 2xx 3xx 4xx. Does anyone know how I could get MATLAB to produce all the possible combinations?
Thank you so much for your time Colby

Respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by