How to create a matrix that has zero in middle?
Show older comments
function x=cancel_middle1(n,A)
x=n;
x(size(n)-A:end-1,size(n)-A:end-1)=0;
got answer here
cancel_middle1(ones(7),3)
ans =
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 1 0 0 0 1
1 1 1 0 0 0 1
1 1 1 0 0 0 1
1 1 1 1 1 1 1
and
cancel_middle1(ones(7),5)
ans =
1 1 1 1 1 1 1
1 0 0 0 0 0 1
1 0 0 0 0 0 1
1 0 0 0 0 0 1
1 0 0 0 0 0 1
1 0 0 0 0 0 1
1 1 1 1 1 1 1
I want input cancel_middle1(ones(7),3) to be
cancel_middle1(ones(7),3)
ans =
1 1 1 1 1 1 1
1 1 1 1 1 1 1
1 1 0 0 0 1 1
1 1 0 0 0 1 1
1 1 0 0 0 1 1
1 1 1 1 1 1 1
1 1 1 1 1 1 1
How can I fix my function?
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!