How to replace diagonal of square matrices within a cell array?
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a 940X1 cell array where each element is a 298X298 square matrix. I want to replace the main diagonals of each square matrix with zero. Is there a way to do it?
댓글 수: 0
채택된 답변
Star Strider
2021년 9월 11일
The easiest way is to subtract the diagonal of each matrix from the matrix —
C = {rand(4); rand(4); rand(4)}
Cr = cellfun(@(x) x-diag(x), C, 'Unif',0)
Cr{1}
Cr{3}
Make appropriate changes to get different results.
.
댓글 수: 8
추가 답변 (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!