Is there a way to fill a matrix around the diagonals?

10 次查看(过去 30 天)
I have a vector that I need to use to fill in the rows of a matrix. This vector will repeat over each row in the matrix except for the indices corresponding to the diagonals. Is there any way to do this without the need of a for loop?

采纳的回答

David Hill
David Hill 2020-4-10
What are the values for the diagonals? I assume you are talking about a square matrix. The below zeros out the diagonals.
x=repmat(v,length(v),1).*~eye(length(v)).*rot90(~eye(length(v)));
  6 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by