The immediate problem is that you initialized i to zero and so the first time there's a new entry added the subscript for L(i,:) is L(0,:).

Either initialize i=1; or move the increment to be before the first usage.

But, the ismember() usage isn't right, anyway...remember the 'rows' optional argument? Plus, it returns a logical array which will be T iff each member is T. If the idea is to not have any duplicates in L, then