create a matrix of combinations

1 次查看(过去 30 天)
Colby
Colby 2016-7-20
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

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by