f



changing the diagonal of a matrix

I feel like this should be quite simple, but am having trouble figuring out how to do the following.  I would like to be able to change the diagonal of a matrix to whatever I choose; more specifically, I need to create a matrix of random numbers with zeros on the diagonal.  I can create the matrix, but I am having trouble finding a function to change the diagonal. 

Any help would be greatly appreciated!
0
salasa (4)
2/12/2009 7:14:02 PM
comp.soft-sys.matlab 211266 articles. 21 followers. lunamoonmoon (257) is leader. Post Follow

2 Replies
312 Views

Similar Articles

[PageSpeed] 31

One approach:

A = rand(5);
A + diag(-diag(A))
0
spamanon (2437)
2/12/2009 7:21:02 PM
Another:

N = 6;
A = rand(N);
A(linspace(1,N^2,N)) = 0
0
spamanon (2437)
2/12/2009 7:25:04 PM
Reply: