how to insert diganole of zeros in to matrix without using loops ?

1 Ansicht (letzte 30 Tage)
my question is simple how to change the main diagonel of nXn of random numers and change the main diagonle to zeroes ?
without using loops ?

Akzeptierte Antwort

madhan ravi
madhan ravi am 3 Mär. 2019
a(logical(eye(size(a,1))))=0 % where a is your matrix
  2 Kommentare
tomer polsky
tomer polsky am 3 Mär. 2019
thank you for your help but why did you use the logical command ?
madhan ravi
madhan ravi am 3 Mär. 2019
Bearbeitet: madhan ravi am 3 Mär. 2019
logical indexing
Alternative (faster):
a(1:size(a,1)+1:end)=0

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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