MATLAB: Draw boundary around grid of data of two classes

boundarycontourplot

I have a grid of positive (red +) and negative (blue o) data plotted as seen below:
I'm looking to draw a boundary around the positive and negative data such as to get something like:
I've been hinted at the contour and contourf function, but am not sure how to make those work to draw such a boundary. contourf seems to give the fill I am looking for as well, but a simple boundary would suffice if the fill is otherwise much more difficult to obtain.
The grid of points X is a 1600×2 matrix (creating the 40×40 grid you see above) and the corresponding positive/negative class labels are y, which is a 1600×1 vector. y(k) == 1 represents positive class, y(k) == 0 represents negative class.
The current code to plot the data is:
% Create New Figure
figure; hold on;
% Find Indices of Positive and Negative Examples
pos = find(y==1); neg = find(y==0);
% Plot Examples
plot(X(pos, 1), X(pos, 2), 'r+');
plot(X(neg, 1), X(neg, 2), 'bo');
hold off;
If it helps, X was created using a meshgrid call.

Best Answer

You can restrict contour to draw only one contour line. See Display Single Contour Line in the contour documentation.