build a special matrix using a for loop
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!