How to generate all possible matrices with the given entries?
1 次查看(过去 30 天)
显示 更早的评论
I have 9 different entries (11,12,13,21,22,23,31,32,33). I want to generate all possible 3 by 3 matrices consisting of these entries with the condition that there is no repetition of any entry in any row and in any column. In short, all the 9 entries in each possible 3 by 3 matrix should be different.
回答(1 个)
KSSV
2018-1-26
val = [11,12,13,21,22,23,31,32,33] ;
A = perms(val) ;
iwant = zeros(3,3,size(A,1)) ;
for i = 1:size(A,1)
iwant(:,:,i) = reshape(A(i,:),3,3) ;
end
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Random Number Generation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!