[w1,w2]=meshgrid(0:pi/20:pi,0:pi/20:pi);
w1 and w2 are going to be 21 x 21 regardless of the inputs.
NP1 is going to be 1 more than the input value NP.
for i1=1:NP1
for i2=i1:NP1
i1 and i2 both have maximum values of NP1, which is 1 more than the input value NP.
fn(i1,i2)=abs(fmod(i2,i1)./(sqrt(fhat(i1).*fhat(i2).*fhat(i1+i2-1))));
fn(i2,i1)=fn(i1,i2);
i1 and i2 can both go as high as NP1, so fn will be NP1 by NP1, where NP1 is 1 more than the input value NP. (By the way, have you considered pre-allocating fn ?)
w1 and w2 are 21 x 21 regardless of the input, but fn is NP1 x NP1 where NP1 is 1 more than the input value NP.
You will have a conflict except in the case where the input value NP is 20.
Best Answer