As z is an array, the following two statements
and
will only be true if every element within z satisfies the conditions, so you always end up with the third result (k=z-100).
To apply the if elseif statements to every element within z, try
x=0:300;
y=x;
[xx,yy]=meshgrid(x,y);
z=(xx+yy)/2;
figure
surf(x,y,z,'EdgeColor','none')
k = z;
k(z>=100) = z(z>=100)-100;
k(z>=100&z<200) = 100;
figure
surf(x,y,k,'EdgeColor','none')
Best Answer