How would I use loops to set certain values in a martix to 0?

1 回表示 (過去 30 日間)
Kylenino Espinas
Kylenino Espinas 2020 年 10 月 23 日
コメント済み: Kylenino Espinas 2020 年 10 月 23 日
I want to make a function that turns every value but the values in a diagonal shape for a matrice.
function [X] = threeMatrices(matrice)
X = matrice;
X(1,2) = 0;
X(1,3) = 0;
X(2,1) = 0;
X(2,3) = 0;
X(3,1) = 0;
X(3,2) = 0;
end
But this doesn't work with matrices of random sizes. Am I supposed to use a loop or anything?

採用された回答

Voss
Voss 2020 年 10 月 23 日
X(~eye(size(X))) = 0;
  1 件のコメント
Kylenino Espinas
Kylenino Espinas 2020 年 10 月 23 日
If I wanted to do the opposite of the diagonal and do everything but it, how would I change it?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by