build a special matrix using a for loop
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
I tried to build a (9,9) matrix that will look like that:
% code
first row: 000000009
second row: 000000088
third row : 000000777
forth row : 000006666
fifth row : 000055555
6th row : 000444444
7th row : 003333333
8th row : 022222222
9th row : 111111111
my code is:
% code
mymat=zeros(9,9);
for ii=1:(size(mymat,1))
for jj=1:(size(mymat,2))
mymat(ii,[9(10-jj)])= 10-ii;
end
end
the result is this:
% code
0 0 0 0 0 0 0 0 9
0 0 0 0 0 0 0 0 8
0 0 0 0 0 0 0 0 7
0 0 0 0 0 0 0 0 6
0 0 0 0 0 0 0 0 5
0 0 0 0 0 0 0 0 4
0 0 0 0 0 0 0 0 3
0 0 0 0 0 0 0 0 2
0 0 0 0 0 0 0 0 1
what am I doing wrong?
0 Kommentare
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!