How to set the diagonal of a cell array of matrices?
조회 수: 12(최근 30일)
표시 이전 댓글
Hi,
I'm looking to set the diagonal of my cell array to identity, specifically eye(3,3). I know a simple for loop solution exists, but if there's something more elegant please let me know.
Thank you.
댓글 수: 0
채택된 답변
Jos (10584)
2019년 10월 29일
Well found, Mohammed! You should put as an answer here :-)
Here is another method
A = cell(4,4) % a cell array
n = size(A,1)
A(1:(n+1):end) = {eye(3,3)}
추가 답변(1개)
참고 항목
범주
Find more on Operating on Diagonal Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!