MATLAB: How to make a loop to add 3 elemts in matrix of zeros(n,n)

placeofzero

n= input('enter the value of n:-->');
A= zeroes(n,n); %n must be greater than 3
i want to add [1 4 1] in second row after skipping first 0 if n=4
and if n=5 add [1 4 1] in second row after skipping first 0 and add [ 1 4 1] to third row after skip two 0`s.
for example:
A = [0 0 0;
0 0 0;
0 0 0]
if n=3
add [ 1 4 1] to 2nd row
then
A = [ 0 0 0;
1 4 1;
0 0 0]
if n=4
A = [0 0 0 0;
0 1 4 1;
0 0 0 0]
if n=5
A = [ 0 0 0 0 0;
1 4 1 0 0;
0 1 4 1 0;
0 0 1 4 1;
0 0 0 0 0];
similarly ahead
help me

Best Answer

As i understand, u need this:
n= input('enter the value of n:-->');
A= zeroes(n,n); %n must be greater than 3
for i=2:n-1 % loop from 2nd to (n-1) row
A(i,:)=[zeros(1,i-2),[1 4 1],zeros(1,n-i-1)] %explicit structure of row i
end