How to set the diagonal of a cell array of matrices?
8 次查看(过去 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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!