Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
plotting points in different colours

Subject: plotting points in different colours

From: natalie lowery

Date: 21 Jul, 2010 12:24:04

Message: 1 of 5

I've got...
for k=1:K
    for m=(((k-1)*M)+1):(k*M)
        plot (X(m,2), X(m,3), '*')
    end
end

I have N points that I'm plotting and M=N/K.

I want to plot each group of points in the same colour. So for example if K=3 I might want the first N/3 of the points to be red and then the second N/3 to be blue, etc... Of course when K=3 I can do this quite easily by splitting up the cases but for large K I need a general method.

Any ideas? Nat xx

Subject: plotting points in different colours

From: fabio freschi

Date: 21 Jul, 2010 13:02:06

Message: 2 of 5

"natalie lowery" <n.l.h.lowery@student.reading.ac.uk> wrote in message <i26ot4$aj1$1@fred.mathworks.com>...
> I've got...
> for k=1:K
> for m=(((k-1)*M)+1):(k*M)
> plot (X(m,2), X(m,3), '*')
> end
> end
>
> I have N points that I'm plotting and M=N/K.
>
> I want to plot each group of points in the same colour. So for example if K=3 I might want the first N/3 of the points to be red and then the second N/3 to be blue, etc... Of course when K=3 I can do this quite easily by splitting up the cases but for large K I need a general method.
>
> Any ideas? Nat xx

Try this

K = 3; % number of points in each group;
M = 10; % number of groups;

N = M*K; % total number of points

col = repmat(1:M,K,1); % define colors by index value
col = col(:); % now col is Nx1

x = rand(N,1);
y = rand(N,1);

scatter(x,y,30,col(:),'filled')

Fabio

Subject: plotting points in different colours

From: Maxx Chatsko

Date: 21 Jul, 2010 13:03:04

Message: 3 of 5

"natalie lowery" <n.l.h.lowery@student.reading.ac.uk> wrote in message <i26ot4$aj1$1@fred.mathworks.com>...
> I've got...
> for k=1:K
> for m=(((k-1)*M)+1):(k*M)
> plot (X(m,2), X(m,3), '*')
> end
> end


  Split it up and use scatter()
Example from older post:
colors = [ [1;1;1] [1;1;.3] [1;.2;.4] [.5;.6;.2] ];
plot(x1(1,:), x1(2,:), 'o', 'Color', colors)
                  Maxx

           

Subject: plotting points in different colours

From: us

Date: 21 Jul, 2010 13:49:04

Message: 4 of 5

"natalie lowery" <n.l.h.lowery@student.reading.ac.uk> wrote in message <i26ot4$aj1$1@fred.mathworks.com>...
> I've got...
> for k=1:K
> for m=(((k-1)*M)+1):(k*M)
> plot (X(m,2), X(m,3), '*')
> end
> end
>
> I have N points that I'm plotting and M=N/K.
>
> I want to plot each group of points in the same colour. So for example if K=3 I might want the first N/3 of the points to be red and then the second N/3 to be blue, etc... Of course when K=3 I can do this quite easily by splitting up the cases but for large K I need a general method.
>
> Any ideas? Nat xx

a hint:

     help scatter; % <- and siblings...

us

Subject: plotting points in different colours

From: natalie lowery

Date: 22 Jul, 2010 13:03:04

Message: 5 of 5

Thanks I'll have a play around with those ideas.- Nat x

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us