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

6 Ansichten (letzte 30 Tage)
Sohrab Salimian
Sohrab Salimian am 10 Apr. 2020
Kommentiert: Sohrab Salimian am 10 Apr. 2020
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?

Akzeptierte Antwort

David Hill
David Hill am 10 Apr. 2020
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 Kommentare
David Hill
David Hill am 10 Apr. 2020
The above should work for you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by