reshuffle a symmetric matrix
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi all, I have a large symmetric matrix (600*600)and need to reshuffle the elements randomly while keeping the matrix symmetric.
Could anyone help? I shall be grateful.
Regards, Shafique
댓글 수: 0
채택된 답변
Andrei Bobrov
2011년 6월 13일
1.
sz = size(A);
B = zeros(sz);
vtl = nonzeros(tril(reshape(1:numel(A),sz)));
B(tril(true(sz))) = A(vtl( randperm(length(vtl))));
B = B + tril(B,-1).';
2. More variant - don't modify main diagonal
sz = size(A);
B = diag(diag(A));
vtl = nonzeros(tril(reshape(1:numel(A),sz),-1));
B(tril(true(sz),-1)) = A(vtl( randperm(length(vtl))));
B = B + tril(B,-1).';
3. OR main diagonal - zeros (modify last row of the previous cod)
B = B + tril(B,-1).'
댓글 수: 4
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Create Block Masks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!