misc = (X(:,:,1)+X(:,:,2)+X(:,:,3)); misc(misc==0) = 0,0001; X(:,:,1) = X(:,:,1)./misc; X(:,:,2) = X(:,:,2)./misc;