How do you extract diagonal elements of submatrix matrix?
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi, need help:
I have a (nxn) square matrix A. I then created submatrices of (kxk) within matrix A. How do I extract only the diagonal (kxk) submatrices into a separate vector? The command diag(A) does not work; this is maybe because of the submatrices elements that I created. Please advise Thanks!
댓글 수: 0
채택된 답변
Ameer Hamza
2020년 12월 2일
Are the submatrices in cell array? For example, try something like this
n = 9;
A = rand(n);
k = 3;
B = mat2cell(A, k*ones(1,n/k), k*ones(1,n/k));
diag_all = cellfun(@diag, B, 'uni', 0);
댓글 수: 10
Vishnu Pradeep
2021년 12월 2일
Hey guys,
What does the 'uni' argument pertain to?
Couldnt find anything on the web other than the name-value pair 'UniformOutput'. Is this the same?
Thanks!
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!