yusuf
yusuf

Reputation: 3781

Coloring specific points with specific colors on a graph in MATLAB plot

I have "classes", and "inputs" array. Both of arrays' dimensions are 1x2000.

In "classes" array, the clusters of data in "inputs" array are recorded. For instance,

classes = [5, 2, 4, 3, 5, ...]
inputs = [5.234, 6.345, 4.342, 2.532, 5.345, ...]

When I plot "inputs" array like plot(inputs), I want to differently color each data which correspond to the specific clusters in "classes" array.

How can I manage this?

Thanks.

Upvotes: 0

Views: 81

Answers (1)

buzjwa
buzjwa

Reputation: 2652

The simplest solution is to do something like:

x = 1:numel(inputs);
plot(x(classes == 1), inputs(classes == 1), '.b', 
     x(classes == 2), inputs(classes == 2), '.g', 
     x(classes == 3), inputs(classes == 3), '.r');

You can expand on this idea, such as looping over the classes, customizing color ordering, and more. Please add more information to your question if you want a more specific or detailed answer.

Upvotes: 3

Related Questions