필터 지우기
필터 지우기

How to recover a square matrix from its upper triangular cell part?

조회 수: 9 (최근 30일)
Xh Du
Xh Du 2017년 7월 27일
댓글: Xh Du 2017년 7월 28일
Hi all,
I'd like to compute the upper triangular part only for a symmetric matrix in a block by block way. After some operations I got this:
K>> tempBlk{:}
ans =
[6x6 double] [6x5 double] [6x5 double] [6x5 double]
[] [5x5 double] [5x5 double] [5x5 double]
[] [] [5x5 double] [5x5 double]
[] [] [] [5x5 double]
The cell blocks in the diagonal line here are full, symmetric, and the non-diagonal cell blocks are full, non-symmetric. The entire symmetric matrix result should be 21 by 21, which has the length and width of 6+5+5+5. I'd like to fill the empty cells (these [ ]) with zeros, then use cell2mat to transform it back to scalar matrix, then use triu to take only the upper triangular part.
Any idea of how to do this? Thanks!

채택된 답변

Matt J
Matt J 2017년 7월 27일
편집: Matt J 2017년 7월 27일
There's no reason to fill the [] cells with zeros. You can fill them with anything, since they will eventually be overwritten with zeros by triu. I would therefore do as follows:
idx=cellfun('isempty', yourCellArray);
C=cellfun(@transpose,yourCellArray.','uni',0);
yourCellArray(idx)=C(idx);
result = triu(cell2mat(yourCellArray))
  댓글 수: 5
Matt J
Matt J 2017년 7월 27일
Probably, but it will amount to a 25% saving at best. It would be better if, instead of cell2mat, you just allocated the final matrix at the very beginning and wrote into the blocks.
Xh Du
Xh Du 2017년 7월 28일
Thank you, this is very helpful!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by