# MATLAB: If loop insede for loop

for

There is an 'if' loop inside a 'for' loop. This loop takes values according to the values of z. For example, when real (z)> 0 and imag (z)> 0, it enters an if loop again. and if (real (z) <1) & (imag (z) <1) gets bhat = 0,0,0,0. but this loop is not working and I could not find the problem. thanks for the answers. code ;
for k = 1 :length(z)            if (real(z)>0) & (imag(z)>0)                if (real(z)<1) & (imag(z)<1)                    bhat(k) = [0;0;0;0];                elseif(real(z)>1) & (imag(z)<1)                    bhat(k) = [0;1;0;0];                elseif(real(z)>1) & (imag(z)>1)                    bhat(k) = [0;1;0;1];                elseif (real(z)<1) & (imag(z)>1)                    bhat(k) = [0;0;0;1];                end                            elseif (real(z)<0) & (imag(z)>0)                if (real(z)>-1) & (imag(z)<1)                    bhat(k) = [1;0;0;0];                elseif (real(z)<-1) & (imag(z)<1)                    bhat(k) = [1;1;0;0];                elseif(real(z)<-1) & (imag(z)>1)                    bhat(k) = [1;1;0;1];                elseif (real(z)>-1) & (imag(z)<1)                    bhat(k) = [1;0;0;1];                end                            elseif (real(z)<0) & (imag(z)<0)                if (real(z)>-1) & (imag(z)>-1)                    bhat(k) = [1;0;1;0];                elseif (real(z)<-1) & (imag(z)>-1)                    bhat(k) = [1;1;1;0];                elseif (real(z)<-1) & (imag(z)<-1)                    bhat(k) = [1;1;1;1];                elseif (real(z)>-1) & (imag(z)<-1)                    bhat(k) = [1;0;1;1];                end                            elseif (real(z)>0) & (imag(z)<0)                if (real(z)<1) & (imag(z)>-1)                    bhat(k) = [0;0;1;0];                elseif (real(z)>1) & (imag(z)>-1)                    bhat(k) = [0;1;1;0];                elseif (real(z)>1) & (imag(z)<-1)                    bhat(k) = [0;1;1;1];                elseif (real(z)<1) & (imag(z)<-1)                    bhat(k) = [0;0;1;1];                end            end        end

bhat(:, k) = whatever