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 CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by