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

1 回表示 (過去 30 日間)
tomer polsky
tomer polsky 2019 年 3 月 3 日
編集済み: madhan ravi 2019 年 3 月 3 日
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 ?

採用された回答

madhan ravi
madhan ravi 2019 年 3 月 3 日
a(logical(eye(size(a,1))))=0 % where a is your matrix
  2 件のコメント
tomer polsky
tomer polsky 2019 年 3 月 3 日
thank you for your help but why did you use the logical command ?
madhan ravi
madhan ravi 2019 年 3 月 3 日
編集済み: madhan ravi 2019 年 3 月 3 日
logical indexing
Alternative (faster):
a(1:size(a,1)+1:end)=0

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by