Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Element by element operation

조회 수: 2 (최근 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