Make a function tha makes zero certain elements of the matrix corners as shown below
Show older comments
for example:
8 1 6
3 5 7
4 9 3
becomes
0 1 0
3 5 7
0 9 0
another example:
17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9
becomes
0 0 1 0 0
0 5 7 14 0
4 6 13 20 22
0 12 19 21 0
0 0 25 0 0
Answers (2)
Azzi Abdelmalek
on 21 May 2016
n=5
A=randi(5,n) % ---Example-----
[n,m]=size(A)
nn=fix(n/2)
id=[1:nn n-nn+1:n]
A(id,[1 n])=0
A([1 n],id)=0
1 Comment
Emmanuel Gutierrez
on 21 May 2016
Andrei Bobrov
on 21 May 2016
Edited: Andrei Bobrov
on 21 May 2016
Please use strel from Image Processing Toolbox
A = [17 24 1 8 15
23 5 7 14 16
4 6 13 20 22
10 12 19 21 3
11 18 25 2 9];
SE = strel('diamond',floor(size(A,1)/2));
out = A.*SE.Neighborhood
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!