You can use SCATTER to easily plot data with different colors. I agree with @gnovice on using classID
instead of class
, by the way.
scatter(X(:,1),X(:,2),6,classID); %# the 6 sets the size of the marker.
EDIT
If you want to display a legend, you have to either use @yuk's, or @gnovice solution.
GSCATTER
%# plot data and capture handles to the points
hh=gscatter(randn(100,1),randn(100,1),randi(3,100,1),[],[],[],'on');
%# hh has an entry for each of the colored groups. Set the DisplayName property of each of them
set(hh(1),'DisplayName','some group')
PLOT
%# create some data
X = randn(100,2);
classID = randi(2,100,1);
classNames = {'some group','some other group'}; %# one name per class
colors = hsv(2); %# use the hsv color map, have a color per class
%# open a figure and plot
figure
hold on
for i=1:2 %# there are two classes
id = classID == i;
plot(X(id,1),X(id,2),'.','Color',colors(i,:),'DisplayName',classNames{i})
end
legend('show')
You may also want to have a look at grouped data if you have the statistics toolbox.