フィルターのクリア

Matrix of statuses or matching; discrete one-to-one mapping

2 ビュー (過去 30 日間)
Alexander
Alexander 2012 年 4 月 30 日
Hello,
I need to create all possible matricies of zeros and ones, where the sums of rows and columns is 1, while the size of the matrix is NxK, where N and K are predefined variables. Is there a simple function for this problem?

採用された回答

Dr. Seis
Dr. Seis 2012 年 4 月 30 日
You can't do this with any old NxK matrix, it must be a square NxN matrix. Otherwise your condition, that the sums of individual rows are 1 and sums of individual cols are also 1, will not be valid. There isn't a simple function (that I know of), but there is a simple solution (provided you are not trying to find for large N). See the example below for N = 4:
N = 4;
A = eye(N);
B = perms(1:N);
C = zeros(N,N,size(B,1));
for ii = 1 : size(B,1)
C(:,:,ii) = A(:,B(ii,:));
end
disp(C)
  1 件のコメント
Alexander
Alexander 2012 年 4 月 30 日
Fantastico! Perms!
Thank you very much.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by