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!