Hi Tzach Berlinsky,
In the code you have provided using nested loops is not necessary. Since the body of loops is executed only when i==j, elimination of one loop can be an option. Replace the nested loops with the following.
for i=4:(n-3)
A(i,i)=4;
A(i,i+1)=-1;
A(i,i-1)=-1;
A(i,i+3)=-1;
A(i,i-3)=-1;
A(i+1,i)=-1;
A(i-1,i)=-1;
A(i+3,i)=-1;
A(i-3,i)=-1;
end
Here is the link to best practices that can be followed to improve performance. You may find it helpful.