Вы можете использовать SCATTER , чтобы легко наносить на график данные разными цветами. Я согласен с @gnovice об использовании classID
вместо class
, кстати.
scatter(X(:,1),X(:,2),6,classID); %# the 6 sets the size of the marker.
EDIT
Если вы хотите отобразить легенду, вы должны использовать решение @ yuk или @ gnovice .
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')
ГРАФИК
%# 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')
Возможно, вы захотите взглянуть на сгруппированных данных , если у вас есть набор инструментов статистики.