who is x?
That message is the result of trying to access an non-existent element of the array, such as x(0).
Make sure x has the right size.
By the way, your for-loop code
Is the same that this, in a single line:
y(l) = -( sum(x(:,l).*log(x(:,l))) );