I currently have a vectors of labels, Y, that describes each column of my data matrix X. For instance, if Y=1, then X is of the first class. I'm trying to plot X as a different colour (or shape) based on the value of Y. Is there a faster way of doing this than my code below? I'm currently using a for loop which takes a while when I'm using lots of data.
n = size(Y);
for i = 1:n(2)
if Y(i) == 1
colour = 'y';
shape = 'c';
elseif Y(i) == 2
colour = 'm';
shape = 'c';
elseif Y(i) == 3
colour = 'c';
shape = 'c';
elseif Y(i) == 4
colour = 'r';
shape = 'c';
elseif Y(i) == 5
colour = 'g';
shape = 'c';
elseif Y(i) == 6
colour = 'b';
shape = 'c';
elseif Y(i) == 7
colour = 'k';
shape = 'c';
elseif Y(i) == 8
colour = 'r';
shape = 's';
elseif Y(i) == 9
colour = 'b';
shape = 's';
elseif Y(i) == 10
colour = 'g';
shape = 's';
end
subplot
scatter(X(1,i), X(2,i), 12, colour, shape, 'filled')
hold on
end
You could get rid of all your
if/elseif
loops: