Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matrix: set diagonal to zero

Subject: Matrix: set diagonal to zero

From: jan

Date: 27 Mar, 2003 03:30:53

Message: 1 of 4

Hi,
is there an efficient way to replace diagonal matrix elements by zero?


Jan

Subject: Matrix: set diagonal to zero

From: Sebastien Paris

Date: 27 Mar, 2003 03:44:20

Message: 2 of 4

jan wrote:
>
>
> Hi,
> is there an efficient way to replace diagonal matrix elements by
zero?
>
> Jan
>


Jan,


try


n = 5;


A = randn(n);


A(1:n+1:n*n) = 0;


S├ębastien

Subject: Matrix: set diagonal to zero

From: Steffen Brueckner

Date: 27 Mar, 2003 10:02:41

Message: 3 of 4

jan wrote:
> Hi,
> is there an efficient way to replace diagonal matrix elements by zero?

A =3D A - diag(diag(A));

steffen
--=20
Steffen Brueckner
brueckner@sbrs.net
http://www.sbrs.net
ISD Uni Stuttgart

Subject: Matrix: set diagonal to zero

From: Franck Dernoncourt

Date: 17 Dec, 2013 06:48:05

Message: 4 of 4

"Steffen Brueckner" <news@sbrs.net> wrote in message <b5ueni$5gk$1@news.BelWue.DE>...
> jan wrote:
> > Hi,
> > is there an efficient way to replace diagonal matrix elements by zero?
>
> A =3D A - diag(diag(A));
>
> steffen
> --=20
> Steffen Brueckner
> brueckner@sbrs.net
> http://www.sbrs.net
> ISD Uni Stuttgart

http://stackoverflow.com/a/3963587/395857 :

A = ones(4)
A(logical(eye(size(A)))) = 0

A =

     0 1 1 1
     1 0 1 1
     1 1 0 1
     1 1 1 0

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us