Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Element by element operation

1 回表示 (過去 30 日間)
John Draper
John Draper 2016 年 6 月 25 日
閉鎖済み: Stephen23 2016 年 6 月 25 日
Hi everyone,
I have some 3x3 matrix e.g. a:
if true
a = [1 2 3; 4 5 6; 7 8 9];
I would like to take an individual element and then subtract the surrounding elements to create a 3x3 sub array in the larger 9x9 array. I have written some code that will do this for me:
if true
Av1 = a(1,1) - a(1:3,1:3);
Av2 = a(1,2) - a(1:3,1:3);
Av3 = a(1,3) - a(1:3,1:3);
Av4 = a(2,1) - a(1:3,1:3);
Av5 = a(2,2) - a(1:3,1:3);
Av6 = a(2,3) - a(1:3,1:3);
Av7 = a(3,1) - a(1:3,1:3);
Av8 = a(3,2) - a(1:3,1:3);
Av9 = a(3,3) - a(1:3,1:3);
Av = [Av1 Av2 Av3; Av4 Av5 Av6; Av7 Av8 Av9];
However as you can see this code is pretty inelegant and cannot be applied to arrays of different sizes. My question is whether it is possible to shorten the code and make it applicable to arrays of different sizes. Thanks for your time, John.

回答 (0 件)

この質問は閉じられています。

Community Treasure Hunt

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

Start Hunting!

Translated by