MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi
Learn moreOpportunities for recent engineering grads.
Apply TodayNew to MATLAB?
MATLAB Central > MATLAB Newsreader > Replacing the diagonal of a square matrix 

Subject: Replacing the diagonal of a square matrix From: Diego Zegarra Date: 5 Mar, 2009 22:46:02 Message: 1 of 19 
Hey guys, 
Subject: Replacing the diagonal of a square matrix From: us Date: 5 Mar, 2009 23:02:44 Message: 2 of 19 
"Diego Zegarra" 
Subject: Replacing the diagonal of a square matrix From: Matt Fig Date: 5 Mar, 2009 23:03:04 Message: 3 of 19 
For square matrix a: 
Subject: Replacing the diagonal of a square matrix From: John D'Errico Date: 5 Mar, 2009 23:07:04 Message: 4 of 19 
"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gopkna$9cf$1@fred.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: Matt Date: 5 Mar, 2009 23:19:01 Message: 5 of 19 
"Diego Zegarra" <diegozbb@gmail.com> wrote in message <gopkna$9cf$1@fred.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: Matt Fig Date: 5 Mar, 2009 23:30:20 Message: 6 of 19 
"Matt " <xys@whatever.com> wrote in message <gopml5$mmp$1@fred.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: John D'Errico Date: 5 Mar, 2009 23:40:21 Message: 7 of 19 
"Matt " <xys@whatever.com> wrote in message <gopml5$mmp$1@fred.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: John D'Errico Date: 5 Mar, 2009 23:48:05 Message: 8 of 19 
"Matt Fig" <spamanon@yahoo.com> wrote in message <gopnac$89p$1@fred.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: Matt Fig Date: 6 Mar, 2009 00:09:01 Message: 9 of 19 
"John D'Errico" <woodchips@rochester.rr.com> wrote in message 
Subject: Replacing the diagonal of a square matrix From: James Tursa Date: 6 Mar, 2009 01:38:02 Message: 10 of 19 
"Matt Fig" <spamanon@yahoo.com> wrote in message <goppit$c2j$1@fred.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: Matt Date: 6 Mar, 2009 01:45:02 Message: 11 of 19 
Well, I'm finding that both for loops (I fixed my earlier mistake) and while loops are slightly slower than colon notation, but not by much. I do have the accelerator turned on, I think. 
Subject: Replacing the diagonal of a square matrix From: Matt Date: 6 Mar, 2009 01:52:17 Message: 12 of 19 
"James Tursa" <aclassyguywithaknotac@hotmail.com> wrote in message <gopupq$841$1@fred.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: Matt Fig Date: 6 Mar, 2009 02:34:01 Message: 13 of 19 
"Matt " <xys@whatever.com> wrote in message ex array. 
Subject: Replacing the diagonal of a square matrix From: Matt Date: 6 Mar, 2009 03:20:20 Message: 14 of 19 
"Matt Fig" <spamanon@yahoo.com> wrote in message <goq22p$d6c$1@fred.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: Matt Fig Date: 6 Mar, 2009 03:34:02 Message: 15 of 19 
I never deal with sparse matrices. Maybe Tim Davis can explain what is going on. Judging by the similarities in our timings for all the other posts (under the same conditions of course) it seems our machines are similar. But here we disagree. These are my timings on your function (fairly consistently across several runs): 
Subject: Replacing the diagonal of a square matrix From: Arash Amini Date: 11 Oct, 2011 03:11:28 Message: 16 of 19 
To replace diagonal of 
Subject: Replacing the diagonal of a square matrix From: Matt J Date: 11 Oct, 2011 13:50:28 Message: 17 of 19 
"Arash A Amini" wrote in message <j70c50$ls9$1@newscl01ah.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: Bruno Luong Date: 11 Oct, 2011 18:05:27 Message: 18 of 19 
"Matt J" wrote in message <j71hj4$efo$1@newscl01ah.mathworks.com>... 
Subject: Replacing the diagonal of a square matrix From: Matt J Date: 11 Oct, 2011 18:40:31 Message: 19 of 19 
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j720h7$aj5$1@newscl01ah.mathworks.com>... 
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.