create a matrix with ones and zeros
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Tony Montgomery
am 6 Sep. 2014
Kommentiert: Tony Montgomery
am 6 Sep. 2014
in need to create an array of 20-by-20 the first row needs to be 19 ones and 1 zero the first column is all ones the last row is is all ones from the first row first column diagnally to the last row last column needs to be filled with ones, the rest are all zero.
now I can type this all out but there must be a better way
my question is how do i create this array?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 6 Sep. 2014
Bearbeitet: Star Strider
am 6 Sep. 2014
This looks like what you want:
a = ones(1,20);
M = diag(a);
M(1,:) = [ones(1,19) 0];
M(:,1) = a';
M(20,:) = a;
3 Kommentare
Star Strider
am 6 Sep. 2014
My pleasure!
I just realised that I could have used ‘a’ in M(1:) as well:
M(1,:) = [a(1:19) 0];
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Operators and Elementary Operations 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!