How do you extract diagonal elements of a cell array?
조회 수: 5 (최근 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!