How do you extract diagonal elements of a cell array?
10 ビュー (過去 30 日間)
古いコメントを表示
[9;9;9;9;1;1;2;2] [9;2;1;1;2;1;9;9] [9;2;1;1;2;1;9;9]
[9;9;9;9;1;1;2;2] [9;2;1;1;2;1;9;9] [9;2;1;1;2;1;9;9]
0 [2;1;9;2;9;9;9;9] [2;1;9;2;9;9;9;9]
Hi, need help:
i have a cell array like this one, and i need to extract only the elements on the diagonal how can i do?
Please advise Thanks!
0 件のコメント
採用された回答
Max Heimann
2022 年 1 月 14 日
編集済み: Max Heimann
2022 年 1 月 14 日
Assuming your matrix "data" is equal in x and y dimension:
[y,x] = size(data)
selected_values = data([1:y+1:x*y])
Alternatively you could try creating an index matrix with the "eye" command and then use that to select your values from the matrix.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Operating on Diagonal Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!