matrix neighbours chaning with iterations

1 回表示 (過去 30 日間)
Jakub
Jakub 2013 年 11 月 4 日
コメント済み: Jakub 2013 年 11 月 4 日
Imagine I have matrix A=ones(5). I want to change center of the matrix to 17, A(3,3)=17; In next iteration I want to change all points that are next to this 20 to 5. i will have:
1 1 1 1 1
1 5 5 5 1
1 5 17 5 1
1 5 5 5 1
1 1 1 1 1
In next step i want to change all ones to 10. And so on...
10 10 10 10 10
10 5 5 5 10
10 5 17 5 10
10 5 5 5 10
10 10 10 10 10
Any idea how to do this to large matrix? How to adress only the neighbours but not the points "inside"?

採用された回答

Matt J
Matt J 2013 年 11 月 4 日
[M,N]=size(A);
center=size(A)/2+.5;
[I,J]=ndgrid((1:M)-center(1), (1:N)-center(2));
A(:) = 20-5*round(max(abs(I),abs(J)))
  2 件のコメント
Jakub
Jakub 2013 年 11 月 4 日
But what if i want to calculate the value of the "edge" by some formula? I need to adress the points..
Jakub
Jakub 2013 年 11 月 4 日
And i want to have there any random numbers not just 20,15,10,... sorry

サインインしてコメントする。

その他の回答 (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