The problem is because you are looking to index X(ii, jj) but you have defined the bounds of ii and jj as the number of elements in X. To explain more, if X is 4x1 matrix then n = 4, but then when you call ii = 1, jj = 2 in your loops X(1,2) doesn't exist.
I am not entirely sure what you're trying to accomplish, but you might try defining ii and jj as bounded by size of X instead of numel.
for ii = 1:size(X,1)
for jj = 1:size(X,2)
Also, as a side note, you don't need the 'or' portion of your if condition, because it is covered in the first one.
IF X(ii,jj) is greater than or equal to 0 OR X(ii,jj) is equal to 0