ali - your above code sample is incomplete. As the error message is telling you, the variable k is undefined. And from your code, this makes sense as the first line is
plot(x(k),y(k),'r-',x,y,'b*');
which relies on k (and x and y). Given that your code is similar to an example from convhull, it could be that you need to remove the first line and then initialize the output from convhull as
k = convhull(xx,yy);
using a lower case k instead of the upper case K. This assumes that you have already initialized n, x, and y.
And..always step through the code using the MATLAB debugger. It will become much more clear where the error is and what perhaps can be done to rectify it.