Hi everybody,
I have an array, let's say 6x6, how to delete the center of this array. I mean I want to delete 3x3 center of this array.
simple example, if we have an array 6x6 with elements:
6 5 2 2 1 9
4 3 0 1 2 8
5 5 6 2 1 7
9 8 0 1 0 6
4 4 1 1 0 5
2 1 1 2 3 4
and I want to delete the center which are:
6 2
0 1
I hope you could help me, I've tried several time to solve it but I couldn't.
Thanks in advance.

댓글 수: 4

Walter Roberson
Walter Roberson 2017년 10월 27일
What size of output are you expecting? It is not possible to have a numeric array with a "hole" in it.
Image Analyst
Image Analyst 2017년 10월 27일
Plus, [6,2;0,1] is NOT a 3x3 matrix.
Please give an example of what you think the output should be. Remember, it absolutely MUST be rectangular - no blanks or holes can be in the middle of it.
Mohanned Al Gharawi
Mohanned Al Gharawi 2017년 10월 27일
Hi you're right, let's say that in different way. I want to delete specific elements(3x3 or 2x2 whatever) inside a big array, and convert the rest of this array into a vector. Thanks
Mohanned Al Gharawi
Mohanned Al Gharawi 2017년 10월 27일
let say I have an array (4x4): 6 5 2 2 4 3 0 1 5 5 6 2 9 8 0 1 then delete the inside or the center of this array, let's say the elements: 3 0 5 6 and the rest is: 6 5 2 2 4 1 5 2 9 8 0 1 as you see I want the rest as a vector. thanks

댓글을 달려면 로그인하십시오.

 채택된 답변

Star Strider
Star Strider 2017년 10월 27일

0 개 추천

‘I want to delete specific elements(3x3 or 2x2 whatever) inside a big array, and convert the rest of this array into a vector.’
That is straightforward:
A = [6 5 2 2 1 9
4 3 0 1 2 8
5 5 6 2 1 7
9 8 0 1 0 6
4 4 1 1 0 5
2 1 1 2 3 4];
Lidx = sub2ind(size(A), [3 3; 4 4], [3 3; 4 4]);
Center = A(Lidx) % View Elements
A(Lidx) = []; % Delete Elements, Return Vector

댓글 수: 2

Mohanned Al Gharawi
Mohanned Al Gharawi 2017년 10월 27일
Thanks a lot for your respond, there is a small problem cause the answer gives 34 elements and it should be 32 element. So I used: Lidx = sub2ind(size(A), [3 3; 4 4], [3 4; 4 3]); instead of yours and it gave me the right answer; anyhow your code was so helpful for me. Thanks a lot again.
Star Strider
Star Strider 2017년 10월 27일
As always, my pleasure.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

질문:

2017년 10월 27일

댓글:

2017년 10월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by