I think the issue is that you don't want to generate the plot like that; it's slow and makes it hard to label. Check out this solution instead:
Y = 10*rand(100,1);
Ind = rand(100,1) > 0.5;
Ind = Ind + (rand(100,1) > 0.75);
Ind = Ind + 1;
Vals = [1:100]';
plot(Vals(Ind == 1),Y(Ind ==1), 'ro', Vals(Ind == 2), ...
Y(Ind == 2), 'bo', Vals(Ind == 3), Y(Ind == 3), 'go')
legend('Red Data', 'Blue Data', 'Green Data')
This is much more efficient and you don't have to loop over all your points.
So, in your example, you would just go:
i = [1:size(Ind,1)];
plot(i(Ind == 1),Y(Ind ==1), 'ro', i(Ind == 2), ...
Y(Ind == 2), 'bo', i(Ind == 3), Y(Ind == 3), 'go')
legend('Red Data', 'Blue Data', 'Green Data')
Best Answer