The line
x(size(n)-A:end-1,size(n)-A:end-1)=0;
is full of bugs.
First, what is the output of size(n)? It's guaranteed to be a vector with at least 2 elements (more for N-D arrays).
So size(n)-A is a vector with at least 2 elements.
Now what happens when you use a vector with the : operator? It's actually documented: If you specify nonscalar arrays, then MATLAB interprets j:i:k as j(1):i(1):k(1). So, you're always using the 1st index of the vector returned by size, which is the size of the first dimension. The code you've written is equivalent to
x(size(n, 1)-A:end-1,size(n, 1)-A:end-1)=0;
Notice the dimensions you index in size. Are they correct?
The second issue, of course, is that if the intent is for the zeros to be centered in the matrix, you ought to calculate the location of that centre, which you typically get by dividing the size by 2. So somewhere in the code there should be a division by 2,
As this looks like homework, I'm not giving the solution, but that should get you going.
Best Answer