Make entries of first row and column of matrix all equal to zero.
81 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I'm trying to create an nxn matrix that has all entries in the first row and column equal to zero, and also all of the diagonal entries need to be equal to zero. The other entries are random 1's and 0's. I have so far made the diagonals equal to zero but am struggling with making the first row and column equal to zero. Below is what I have so far:
n = 10;
B = randi([0,1],n,n);
v = zeros(1,n);
B = B + diag(v-diag(B));
Thanks
0 Kommentare
Antworten (2)
Fabio Freschi
am 19 Jan. 2020
% nullify first col
B(:,1) = 0;
%nullify first row
B(1,:) = 0;
0 Kommentare
Siehe auch
Kategorien
Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!