フィルターのクリア

build a special matrix using a for loop

1 回表示 (過去 30 日間)
ilona
ilona 2013 年 11 月 24 日
回答済み: ilona 2013 年 11 月 24 日
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?

採用された回答

ilona
ilona 2013 年 11 月 24 日
OMG! sorry I found out that my index was wrong! the correct answer is:
% code
mymat=zeros(9,9);
for ii = 1:(size(mymat,1))
mymat(ii,[(10-ii):9])= 10-ii;
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by