create a matrix of combinations
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!